Browse Source

Add formatting

pull/3/head
Wahyu Ramadhan 1 year ago
parent
commit
a01f1ca25e
  1. 105
      app/Http/Controllers/MapMonitoringController.php

105
app/Http/Controllers/MapMonitoringController.php

@ -15,56 +15,71 @@ class MapMonitoringController extends Controller
// default map monitoring shows today's presence lat lon in the map // default map monitoring shows today's presence lat lon in the map
public function search(Request $request) public function search(Request $request)
{ {
$dateNow = Carbon::today()->addHour(7)->format('Y-m-d'); $dateNow = Carbon::today()->addHour(7)->format('Y-m-d');
// get distinct human assign project // get distinct human assign project
$hr_assign_project = DB::table('assign_hr_to_proyek') $hr_assign_project = DB::table('assign_hr_to_proyek')
->select('user_id') ->select('user_id')
->whereIn('proyek_id', $request->project_id) ->whereIn('proyek_id', $request->project_id)
->distinct() ->distinct()
->get(); ->get();
// get position hr in presensi // get position hr in presensi
$tmp = []; $tmp = [];
foreach($hr_assign_project as $key){ foreach ($hr_assign_project as $key) {
$presensi = DB::table('t_clock_in_out as tcio') $presensi = DB::table('t_clock_in_out as tcio')
->select('tcio.id as clock_in_out_id','mu.id as user_id', 'mu.name as fullname', 'tcio.clock_in', 'tcio.clock_out', 'tcio.clock_in_lat', 'tcio.clock_in_lng', ->select(
'tcio.clock_out_lat', 'tcio.clock_out_lng', 'tcio.clock_in_loc', 'tcio.clock_out_loc', 'tcio.clock_in_boundary', 'tcio.id as clock_in_out_id',
'tcio.clock_out_boundary', 'mu.username', 'tcio.date_presence', 'tcio.created_at') 'mu.id as user_id',
->join('m_users as mu', 'mu.id', '=', 'tcio.user_id') 'mu.name as fullname',
->where('mu.id', $key->user_id) 'tcio.clock_in',
->orderBy('tcio.id', 'DESC') 'tcio.clock_out',
->first(); 'tcio.clock_in_lat',
$project = DB::table('assign_hr_to_proyek as ahtp') 'tcio.clock_in_lng',
->select('ahtp.proyek_id as id', 'mp.nama as project_name') 'tcio.clock_out_lat',
->join('m_proyek as mp', 'mp.id', '=', 'ahtp.proyek_id') 'tcio.clock_out_lng',
->whereIn('ahtp.proyek_id', $request->project_id) 'tcio.clock_in_loc',
->where('ahtp.user_id', $key->user_id) 'tcio.clock_out_loc',
->get(); 'tcio.clock_in_boundary',
if($presensi && isset($presensi->user_id)){ 'tcio.clock_out_boundary',
'mu.username',
'tcio.date_presence',
'tcio.created_at'
)
->join('m_users as mu', 'mu.id', '=', 'tcio.user_id')
->where('mu.id', $key->user_id)
->orderBy('tcio.id', 'DESC')
->first();
$project = DB::table('assign_hr_to_proyek as ahtp')
->select('ahtp.proyek_id as id', 'mp.nama as project_name')
->join('m_proyek as mp', 'mp.id', '=', 'ahtp.proyek_id')
->whereIn('ahtp.proyek_id', $request->project_id)
->where('ahtp.user_id', $key->user_id)
->get();
if ($presensi && isset($presensi->user_id)) {
$image = DB::table('m_image')->select('image')->where('category', 'presensi')->where('ref_id', $presensi->clock_in_out_id)->first(); $image = DB::table('m_image')->select('image')->where('category', 'presensi')->where('ref_id', $presensi->clock_in_out_id)->first();
$tmp[] = array( $tmp[] = array(
'user_id' => $presensi->user_id, 'user_id' => $presensi->user_id,
'clock_in' => $presensi->clock_in, 'clock_in' => $presensi->clock_in,
'clock_out' => $presensi->clock_out, 'clock_out' => $presensi->clock_out,
'date_presence' => $presensi->date_presence, 'date_presence' => $presensi->date_presence,
'clock_in_lat' => $presensi->clock_in_lat, 'clock_in_lat' => $presensi->clock_in_lat,
'clock_in_lng' => $presensi->clock_in_lng, 'clock_in_lng' => $presensi->clock_in_lng,
'clock_out_lat' => $presensi->clock_out_lat, 'clock_out_lat' => $presensi->clock_out_lat,
'clock_out_lng' => $presensi->clock_out_lng, 'clock_out_lng' => $presensi->clock_out_lng,
'clock_in_loc' => $presensi->clock_in_loc, 'clock_in_loc' => $presensi->clock_in_loc,
'clock_out_loc' => $presensi->clock_out_loc, 'clock_out_loc' => $presensi->clock_out_loc,
'clock_in_boundary' => $presensi->clock_in_boundary, 'clock_in_boundary' => $presensi->clock_in_boundary,
'clock_out_boundary' => $presensi->clock_out_boundary, 'clock_out_boundary' => $presensi->clock_out_boundary,
'username' => $presensi->username, 'username' => $presensi->username,
'name' => $presensi->fullname, 'name' => $presensi->fullname,
'image_selfie' => isset($image->image) ? $image->image : '-', 'image_selfie' => isset($image->image) ? $image->image : '-',
'created_at' => $presensi->created_at, 'created_at' => $presensi->created_at,
'presence_status' => $presensi->date_presence == $dateNow ? true : false,//true, //status date_presence, 'presence_status' => $presensi->date_presence == $dateNow ? true : false, //true, //status date_presence,
'projects' => $project 'projects' => $project
); );
} }
} }
return response()->json(['status'=>'success','code'=>200, 'data' => $tmp, 'totalRecord'=>count($tmp)], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $tmp, 'totalRecord' => count($tmp)], 200);
} }
public function list() public function list()
@ -72,12 +87,12 @@ class MapMonitoringController extends Controller
$data = Presence::all(); $data = Presence::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 presence, please try again later!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'failed get list presence, please try again later!', 'code' => 400], 400);
} }
} }
} }
Loading…
Cancel
Save