# Recurring tasks

## Using recurrence

1. In Task Management > Categories, add or edit a category and enable Recurring.
2. Select Daily, Selected Days of the Week, or Monthly. For selected weekdays, tick the days.
3. Create a task and select the category. Its recurrence settings are prefilled; they can be changed or switched off for that task.
4. Select the task owner, start/due dates, target, supervisor and other task details. An end date is optional.
5. Save the task once. Each due occurrence gets its own task with status New and zero achieved progress.

Daily recurrence keeps the original start time. Weekly recurrence uses the selected weekdays. Monthly recurrence uses the original day of the month; if a month is shorter, the last day is used, then the original day resumes next month. Due dates retain the time allowed in the original task, including overnight or multi-day deadlines.

Changing a category only changes defaults for new tasks, not existing schedules. Edit the original recurring task to change future copies. Untick Recurring to stop future copies without deleting previous tasks. Completing the original task does not stop its recurrence; cancelling it does. Category defaults alone never generate unassigned tasks.

## Background scheduler

The application registers `tasks:generate-recurring` to run every minute. Laravel's scheduler must be started by the server operating system. Only configure it once per installation, on the server, not on every cashier's computer.

### Windows / XAMPP

Create a Windows Task Scheduler task that runs whether the user is logged on or not, repeating every minute indefinitely:

- Program: the installation's PHP executable, e.g. `E:\xampp\php\php.exe`
- Arguments: `"E:\xampp\htdocs\jevapos.com\artisan" schedule:run`
- Start in: `E:\xampp\htdocs\jevapos.com`
- If already running: do not start another instance.
- Enable running as soon as possible after a scheduled start is missed.

Replace drive/folder paths with those of the client installation. Use the Windows account under which PHP can access the POS files, database and storage folder. This is separate from the restaurant print agent.

### cPanel / Linux

Add this once to Cron Jobs, once per minute, using the hosting provider's actual PHP executable and POS directory:

```cron
* * * * * /usr/local/bin/php /home/ACCOUNT/pos/artisan schedule:run >> /home/ACCOUNT/pos/storage/logs/scheduler.log 2>&1
```

Rotate or periodically clear the scheduler log. Set `APP_TIMEZONE=Africa/Nairobi` for Kenyan operating times. Task recurrence uses server/application time, not the viewing device's time.

### Testing

```text
php artisan schedule:list
php artisan tasks:generate-recurring
```

The command creates only due tasks and reports the count. Re-running it does not duplicate occurrences. Each command run generates up to 200 copies; large backlogs drain over subsequent runs. If the scheduler is not installed yet, opening Task Management catches up up to 50 copies within the user's accessible branches. This fallback is not a replacement for cron when tasks must appear without anyone opening the module.

Inactive task owners/categories/branches and revoked creator permissions pause generation. Reactivation can catch up missed occurrences. Existing task viewing and editing permissions still apply. SMS preferences are copied, but this feature does not add SMS sending.

## Database upgrade

Run `php artisan migrate --force` after deploying the updated files. The additive migration is `2026_10_10_180000_add_task_recurrence.php`; existing tasks and categories default to non-recurring. Do not recreate or clear task tables.
