Custom Backend OSPRO Surveyor Indonesia
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.7 KiB

<?php
namespace App\Http\Controllers;
use Log;
use Illuminate\Http\Request;
use App\Models\Presence;
use App\Models\Activity;
use App\Models\MapMonitoring;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
class MapMonitoringController extends Controller
{
// default map monitoring shows today's presence lat lon in the map
public function search(Request $request)
1 year ago
{
$dateNow = Carbon::today()->addHour(7)->format('Y-m-d');
// get distinct human assign project
$hr_assign_project = DB::table('assign_hr_to_proyek')
1 year ago
->select('user_id')
->whereIn('proyek_id', $request->project_id)
->distinct()
->get();
// get position hr in presensi
$tmp = [];
1 year ago
foreach ($hr_assign_project as $key) {
$presensi = DB::table('t_clock_in_out as tcio')
1 year ago
->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',
'tcio.clock_in_loc',
'tcio.clock_out_loc',
'tcio.date_presence'
1 year ago
)
->join('m_users as mu', 'mu.id', '=', 'tcio.user_id')
->where('mu.id', $key->user_id)
->orderBy('tcio.clock_in', 'DESC')
1 year ago
->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();
$waypoint = DB::table('m_waypoint')->select('lat', 'lon', 'wptime')->where('user_id', $presensi->user_id)->orderBy('wptime', 'DESC')->first();
$tmp[] = array(
1 year ago
'user_id' => $presensi->user_id,
'wp_lat' => isset($waypoint) ? $waypoint->lat : null,
'wp_lon' => isset($waypoint) ? $waypoint->lon : null,
'wp_time' => isset($waypoint) ? $waypoint->wptime : null,
1 year ago
'clock_in' => $presensi->clock_in,
'clock_out' => $presensi->clock_out,
'clock_in_lat' => $presensi->clock_in_lat,
'clock_in_lng' => $presensi->clock_in_lng,
'clock_in_loc' => $presensi->clock_in_loc,
'clock_out_loc' => $presensi->clock_out_loc,
'name' => $presensi->fullname,
'image_selfie' => isset($image->image) ? $image->image : '-',
'presence_status' => $presensi->date_presence == $dateNow ? true : false, //true, //status date_presence,
'projects' => $project
);
}
}
1 year ago
return response()->json(['status' => 'success', 'code' => 200, 'data' => $tmp, 'totalRecord' => count($tmp)], 200);
}
public function list()
{
$data = Presence::all();
$countData = $data->count();
1 year ago
if ($data) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get list presence, please try again later!', 'code' => 400], 400);
}
}
1 year ago
}