EmployeeAudit extends BaseAudit
Employee audit trail implementations
Table of Contents
Methods
- employeeBankDetailsUpdatedLog() : void
- Log Employee Bank Details update
- employeeCreatedLog() : void
- Log Employee creation
- employeeDeletedLog() : void
- Log Employee deletion
- employeePersonDetailsUpdatedLog() : void
- Log Employee Person Details update
- employeeUpdatedLog() : void
- Log Employee update
- addAuditLog() : void
- Log an audit trail entry
- getCompanyId() : int
- Extract company ID from various model types.
- getUserId() : int
- Get the current authenticated user ID, or fallback to job context user ID.
Methods
employeeBankDetailsUpdatedLog()
Log Employee Bank Details update
public
static employeeBankDetailsUpdatedLog(mixed $oldRecord, mixed $newRecord, int $companyId, mixed $employeeNo[, int $userId = 0 ]) : void
Parameters
- $oldRecord : mixed
-
The Employee bank details before the update
- $newRecord : mixed
-
The Employee bank details after the update
- $companyId : int
-
The Employee's company ID
- $employeeNo : mixed
-
The Employee number
- $userId : int = 0
-
The ID of the user who performed the action (optional)
Tags
employeeCreatedLog()
Log Employee creation
public
static employeeCreatedLog(mixed $record[, int $userId = 0 ]) : void
Parameters
- $record : mixed
-
The newly created Employee record
- $userId : int = 0
-
The ID of the user who performed the action (optional)
Tags
employeeDeletedLog()
Log Employee deletion
public
static employeeDeletedLog(mixed $record[, int $userId = 0 ]) : void
Parameters
- $record : mixed
-
The Employee being deleted
- $userId : int = 0
-
The ID of the user who performed the action (optional)
Tags
employeePersonDetailsUpdatedLog()
Log Employee Person Details update
public
static employeePersonDetailsUpdatedLog(mixed $oldRecord, mixed $newRecord, int $companyId, mixed $employeeNo[, int $userId = 0 ]) : void
Parameters
- $oldRecord : mixed
-
The Employee person details before the update
- $newRecord : mixed
-
The Employee person details after the update
- $companyId : int
-
The Employee's company ID
- $employeeNo : mixed
-
The Employee number
- $userId : int = 0
-
The ID of the user who performed the action (optional)
Tags
employeeUpdatedLog()
Log Employee update
public
static employeeUpdatedLog(mixed $oldRecord, mixed $newRecord[, int $userId = 0 ]) : void
Parameters
- $oldRecord : mixed
-
The Employee data before the update
- $newRecord : mixed
-
The Employee data after the update
- $userId : int = 0
-
The ID of the user who performed the action (optional)
Tags
addAuditLog()
Log an audit trail entry
protected
static addAuditLog(int $companyId, int $userId, string $message, string $module, string $action[, mixed|null $currentRecord = null ][, mixed|null $updatedRecord = null ][, string|null $objectName = null ][, string $queueName = 'audit-trails' ][, bool $afterCommit = false ]) : void
Parameters
- $companyId : int
-
Company identifier
- $userId : int
-
User identifier (default 0 for system actions)
- $message : string
-
Human-readable audit message
- $module : string
-
Module name (PAYROLL, LEAVE, PAYMENTS, etc.) - must be a valid AuditModulesEnum value
- $action : string
-
Action type (CREATE, UPDATE, DELETE, etc.) - must be a valid AuditActionsEnum value
- $currentRecord : mixed|null = null
-
Current data being logged
- $updatedRecord : mixed|null = null
-
The updated data (for updates)
- $objectName : string|null = null
-
Optional name of the object being logged - if not provided, will be inferred from the model
- $queueName : string = 'audit-trails'
-
Optional queue name for async processing. Default 'audit-trails'
- $afterCommit : bool = false
-
Whether to log after DB commit
Tags
getCompanyId()
Extract company ID from various model types.
protected
static getCompanyId(mixed $model) : int
This method attempts to determine the company ID from the provided model instance.
It checks for a direct company_id property or navigates through related employee models.
Parameters
- $model : mixed
-
Model instance
Tags
Return values
int —Company ID
getUserId()
Get the current authenticated user ID, or fallback to job context user ID.
protected
static getUserId() : int
This method first checks for an authenticated user via the auth() helper. If no user is authenticated, it looks for a user_id in the job context (for queued jobs).
To add a user ID to the job context, you can use this in your job setup:
app()->instance('job_context', ['user_id' => $userId]);
If neither is available, it returns 0 to indicate a system action.
Return values
int —The determined user ID, or 0 if none found