# Employee task workflow

Employees use **My Tasks** (`/admin/my-tasks`) to create a task assigned to themselves. The form accepts title, description, due date, priority and an initial Pending/In progress status. The server fixes the assignee and creator from the signed-in account; an active employee profile is required.

**Start task** changes Pending to In progress and records `started_at`. **Complete task** changes In progress to Completed (`done`) and records `completed_at`. An employee must start before completing and cannot reopen a closed task. Creating a task as In progress starts it immediately. Duplicate submissions preserve the recorded times, and updates lock the row to serialize competing requests. The same timing applies to visa tasks on My Tasks; website visa submissions continue to use their existing review screen.

Admins use **HR & Payroll → Tasks** (`/admin/tasks`) for general task history, including employee-created work. Filters include employee (including inactive/deleted profiles), status, date type (Created/Started/Completed/Due date), and inclusive From/To dates. Leave either end blank for an open range. Results are paginated and preserve filters. Visa application tasks remain managed in their existing visa screens.

Timestamps are stored using the application's UTC clock and displayed in `ATTENDANCE_TIMEZONE` (Asia/Dhaka by default). Timestamp filters convert whole business days to UTC boundaries; due dates remain calendar dates. Admins can reopen general tasks: completion clears, first start remains, and completing again records a new completion time. This is a task history list, not a per-transition time sheet.

Existing historical records retain their existing completion time, if any. Missing historical start/end times are shown as unknown; the migration does not infer times from creation or update dates.

## Deployment

Deploy code and run `php artisan migrate --force` before serving the updated screens. Migration `2026_10_19_000002_add_task_work_times.php` adds `tasks.started_at`, visa task start/completion fields, a task history index, and the new `admin.my-tasks.store` permission. Existing roles with the own-task status permission receive own-task creation permission. New employee roles receive it through `EmployeeRoleSeeder`. Custom roles can be adjusted through the role editor.

No frontend build is needed for these Blade screens. The migration has been exercised in the test database; it has not been applied to production.

## Verification

`php artisan test --compact --filter='EmployeeTaskWorkflowTest|VisaApplicationOwnershipTest|RolePermissionTest'`

Tests cover employee task creation, forged assignment/timestamp protection, inactive profiles, ownership and admin access, start/complete order, duplicate submissions, admin reopen semantics, local date boundaries, one-sided filters, pagination, visa task timing, migration rollback/reapply, and permission upgrades.
