login api : GWM
This commit is contained in:
parent
34c5332b5e
commit
80a168ec0e
@ -64,6 +64,8 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) {
|
||||
$routes->post('staff/changeStaffStatus', 'StaffController::changeStaffStatus');
|
||||
$routes->get('staff/managerIncentiveFileList', 'StaffController::managerIncentiveFileList');
|
||||
$routes->get('staff/downloadManagerIncentiveFile', 'StaffController::downloadManagerIncentiveFile');
|
||||
$routes->get('staff/monthlyLoginCount', 'StaffController::monthlyLoginCount');
|
||||
$routes->get('staff/staffLoggedDays', 'StaffController::staffLoggedDays');
|
||||
|
||||
|
||||
//Enquiry
|
||||
|
||||
@ -260,6 +260,71 @@ class StaffController extends ResourceController
|
||||
}
|
||||
|
||||
|
||||
public function monthlyLoginCount()
|
||||
{
|
||||
$month = $this->request->getGet('month') ?? date('Y-m'); // Default: current month
|
||||
|
||||
// Extract year-month format (e.g., '2025-10')
|
||||
$startDateTime = date('Y-m-01 00:00:00', strtotime($month));
|
||||
$endDateTime = date('Y-m-t 23:59:59', strtotime($month));
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
$builder = $db->table('partner_staff_attendance a');
|
||||
$builder->select('a.staff_id , s.name AS staff_name, DATE_FORMAT(a.login_datetime, "%Y-%m") AS month, COUNT(a.id) AS login_count');
|
||||
$builder->join('partner_staff s', 's.id = a.staff_id', 'left');
|
||||
$builder->where('a.login_datetime >=', $startDateTime);
|
||||
$builder->where('a.login_datetime <=', $endDateTime);
|
||||
$builder->groupBy('a.staff_id');
|
||||
$builder->groupBy('month');
|
||||
$builder->orderBy('s.name', 'ASC');
|
||||
|
||||
$result = $builder->get()->getResultArray();
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'month' => $month, 'data' => $result], 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function staffLoggedDays()
|
||||
{
|
||||
$staffId = $this->request->getGet('staff_id');
|
||||
$month = $this->request->getGet('month') ?? date('Y-m');
|
||||
|
||||
$startDateTime = date('Y-m-01 00:00:00', strtotime($month));
|
||||
$endDateTime = date('Y-m-t 23:59:59', strtotime($month));
|
||||
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
$builder = $db->table('partner_staff_attendance');
|
||||
$builder->select('DATE(login_datetime) AS login_date, MIN(login_datetime) AS first_login, MAX(logout_datetime) AS last_logout');
|
||||
$builder->where('staff_id', $staffId);
|
||||
$builder->where('login_datetime >=', $startDateTime);
|
||||
$builder->where('login_datetime <=', $endDateTime);
|
||||
$builder->groupBy('DATE(login_datetime)');
|
||||
$builder->orderBy('login_date', 'ASC');
|
||||
|
||||
$records = $builder->get()->getResultArray();
|
||||
|
||||
// Format result
|
||||
$formatted = [];
|
||||
foreach ($records as $row) {
|
||||
$formatted[] = [
|
||||
'login_date' => $row['first_login'] ? date('d, M Y h:i A', strtotime($row['first_login'])) : null,
|
||||
'logout_date' => $row['last_logout'] ? date('d, M Y h:i A', strtotime($row['last_logout'])) : null,
|
||||
];
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'month' => $month,
|
||||
'data' => $formatted
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user