Browse Source

Merge pull request 'fix search task mobile' (#189) from dev-wahyu into staging

Reviewed-on: ordo/adw-backend#189
pull/3/head
ibnu 1 year ago
parent
commit
aa582c4cff
  1. 1238
      app/Http/Controllers/PresenceController.php
  2. 419
      app/Http/Controllers/UserToActivityController.php

1238
app/Http/Controllers/PresenceController.php

File diff suppressed because it is too large Load Diff

419
app/Http/Controllers/UserToActivityController.php

@ -1,199 +1,220 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\UserToActivity; use App\Models\UserToActivity;
use App\Models\Activity; use App\Models\Activity;
use Datatables; 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'
]); ]);
$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,
"role_proyek_id" => $users_role[$index], "role_proyek_id" => $users_role[$index],
"proyek_id" => $request->proyek_id, "proyek_id" => $request->proyek_id,
"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)) if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = 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==""){ if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die(); die();
} }
$result = 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 search(Request $request) public function search(Request $request)
{ {
$payload = $request->all(); $payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_activity'); if (isset($payload['join_column'])) {
$builder = $dataBuilder['builder']; $join_column = $payload['join_column'];
$countBuilder = $dataBuilder['count']; unset($payload['join_column']);
$dataGet = $builder->get(); }
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); $dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_activity');
} $builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
public function list() if (isset($join_column)) {
{ $startDate = $join_column['start_date'];
$data = UserToActivity::all(); $endDate = $join_column['end_date'];
$countData = $data->count(); $startDate = date("Y-m-d H:i:sO", strtotime($startDate));
$endDate = date("Y-m-d H:i:sO", strtotime($endDate));
if($data){ $builder->where(function ($query) use ($startDate, $endDate) {
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); $query
}else{ ->where('m_proyek.mulai_proyek', '>=', $startDate)
return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); ->where('m_proyek.akhir_proyek', '<=', $endDate)
} ->where(function ($query) use ($endDate, $startDate) {
} $query
->where('m_activity.start_date', '>=', $startDate)
public function listFiltered(Request $request) ->where('m_activity.end_date', '<=', $endDate);
{ });
$startDate = $request->start_date; });
$endDate = $request->end_date; }
$userId = $request->user_id; $dataGet = $builder->get();
$proyekId = $request->proyek_id; $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
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') public function list()
->where('m_activity.start_date', '=', $startDate) {
->where('m_activity.end_date', '=', $endDate) $data = UserToActivity::all();
->where('assign_hr_to_activity.user_id', '=', $userId) $countData = $data->count();
->where('assign_hr_to_activity.proyek_id', '=', $proyekId)
->get(); if($data){
}else { return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
$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') }else{
->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id') return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400);
->where('m_activity.start_date', '=', $startDate) }
->where('m_activity.end_date', '=', $endDate) }
->where('assign_hr_to_activity.user_id', '=', $userId)
->get(); public function listFiltered(Request $request)
} {
$countData = $data->count(); $startDate = $request->start_date;
$endDate = $request->end_date;
if($data){ $userId = $request->user_id;
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); $proyekId = $request->proyek_id;
}else{
return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); 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)
public function datatables(Request $request){ ->where('m_activity.end_date', '=', $endDate)
$id_activity = $request->query('idact'); ->where('assign_hr_to_activity.user_id', '=', $userId)
$data = UserToActivity::select("assign_hr_to_activity.id as id", "u.name as user_name", "mrp.name as role_name") ->where('assign_hr_to_activity.proyek_id', '=', $proyekId)
->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id") ->get();
->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id") }else {
->where('assign_hr_to_activity.activity_id', $id_activity) $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')
->get(); ->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id')
return Datatables::of($data) ->where('m_activity.start_date', '=', $startDate)
->addIndexColumn() ->where('m_activity.end_date', '=', $endDate)
->addColumn('action', function($row){ ->where('assign_hr_to_activity.user_id', '=', $userId)
$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>'; ->get();
return $actionBtn; }
}) $countData = $data->count();
->rawColumns(['action'])->make(true);
} 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);
}
}

Loading…
Cancel
Save