# Cron Job Information

The application uses `node-cron` to schedule the following background tasks.

## 1. Account Deletion Check
- **Schedule**: `0 2 * * *` (Daily at 2:00 AM Server Time)
- **File**: `backend/src/jobs/deletionCron.js`
- **Description**: Checks for companies that have requested account deletion and are scheduled for today or earlier.
- **Actions**:
    - Deletes all Forms associated with the company.
    - Deletes all Submissions associated with the company.
    - Deletes the company's profile photo (logo).
    - Deletes the Company record itself.

## 2. Plan Expiry Check
- **Schedule**: `30 3 * * *` (Daily at 03:30 UTC = 9:00 AM IST)
- **File**: `backend/src/services/cronService.js` (Function: `checkExpiringPlans`)
- **Description**: Checks for paid plans (non-free) that are expiring soon.
- **Actions**:
    - Checks for companies with plans expiring in exactly 7, 3, or 1 days.
    - Sends a payment reminder email.
    - Sends a push notification (`plan_expiry`) if an FCM token is available.

## 3. Daily Summary
- **Schedule**: `30 14 * * *` (Daily at 14:30 UTC = 8:00 PM IST)
- **File**: `backend/src/services/cronService.js` (Function: `dailySummary`)
- **Description**: Sends a summary of new leads received today.
- **Actions**:
    - Counts submissions received since the start of the day.
    - Sends a push notification (`daily_summary`) with the count if (> 0).

## 4. Weekly Report
- **Schedule**: `30 11 * * 0` (Weekly on Sunday at 11:30 UTC = 5:00 PM IST)
- **File**: `backend/src/services/cronService.js` (Function: `weeklyReport`)
- **Description**: Sends a summary of new leads received over the past week.
- **Actions**:
    - Counts submissions received in the last 7 days.
    - Sends a push notification (`weekly_report`) with the count if (> 0).

## 5. Inactive Company Alert
- **Schedule**: `30 4 * * 1` (Weekly on Monday at 04:30 UTC = 10:00 AM IST)
- **File**: `backend/src/services/cronService.js` (Function: `inactiveCompanyAlert`)
- **Description**: Identifies companies that have been inactive for more than 30 days.
- **Actions**:
    - Checks companies created more than 30 days ago.
    - Checks if they have NO submissions OR their last submission was > 30 days ago.
    - Sends an Admin Notification (`inactive_alert`).

## 6. Expired Plan Check
- **Schedule**: `1 0 * * *` (Daily at 00:01 UTC)
- **File**: `backend/src/services/cronService.js` (Function: `checkExpiredPlans`)
- **Description**: Checks for plans that have actually expired (end date < now).
- **Actions**:
    - Downgrades eligible companies to the 'free' plan.
    - resets limits to free plan defaults.
    - Sends a push notification (`plan_expired`).
