> ## Documentation Index
> Fetch the complete documentation index at: https://docs.younegotiate.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Imports, Campaigns & Reports

> Background jobs process creditor profile imports, campaign delivery, and scheduled report emails.

## Real-World Example

Maya uploads creditor profiles in the morning, schedules a campaign in the afternoon, and leaves a weekly report active for Monday. The browser should not stay open for any of that work. Jobs and scheduled commands process the CSV import, campaign delivery, provider tracking, and report email delivery in the background.

## Visual Flow

```mermaid placement="top-right" actions={true} theme={"system"}
flowchart TD
    A["Upload, campaign, or scheduled report is created"] --> B["Portal stores operational record"]
    B --> C{"Background worker type"}
    C -->|Import| D["Process creditor profile CSV on imports queue"]
    C -->|Campaign| E["Chunk creditor profiles and send emails"]
    C -->|Report| F["Generate CSV and email recipients"]
    D --> G["History shows counts and failed rows"]
    E --> H["Campaign tracker updates from jobs and webhooks"]
    F --> I["Last sent time updates and temp file is deleted"]
    classDef default fill:#F8FAFC,stroke:#64748B,stroke-width:1.5px,color:#0F172A;
    classDef actor fill:#E0F2FE,stroke:#0284C7,stroke-width:2px,color:#0C4A6E;
    classDef system fill:#F8FAFC,stroke:#64748B,stroke-width:1.5px,color:#0F172A;
    classDef decision fill:#FEF3C7,stroke:#D97706,stroke-width:2px,color:#78350F;
    classDef risk fill:#FEE2E2,stroke:#DC2626,stroke-width:2px,color:#7F1D1D;
    classDef outcome fill:#DCFCE7,stroke:#16A34A,stroke-width:2px,color:#14532D;
    class A actor;
    class B,D,E,F system;
    class C decision;
    class G,H,I outcome;
    linkStyle default stroke:#94A3B8,stroke-width:2px;
```

## Background Work

| Area                    | Background Behavior                                                                                                          |
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| Creditor profile import | Stores the CSV, creates import history, processes rows on the `imports` queue, and writes failed rows to a failed CSV.       |
| Campaign delivery       | The daily command finds due campaigns, creates trackers, chunks creditor profiles, and dispatches individual email jobs.     |
| Provider tracking       | SendGrid events update EcoMail Hub campaign sent, delivered, and viewed counts by provider tracking key.                     |
| Scheduled reports       | Daily, weekly, and monthly commands generate CSV files, email recipients, update last sent time, and delete temporary files. |

## How It Should Work

* It should keep long-running import, campaign, and report work outside page requests.
* It should keep each history/tracker/scheduled export scoped to the owning EcoMail Hub user.
* It should make failure visible through upload history, tracker counts, or missing report send state.
* It should avoid duplicate scheduled report sends inside the same frequency window.

## How It Should Not Work

* It should not require a user to keep the browser open while rows or campaign recipients process.
* It should not mix EcoMail Hub tracking with creditor campaign tracking.
* It should not leave temporary scheduled export files around after email delivery.

## Developer Notes

* EcoMail Hub campaigns run daily at 17:30.
* CRM scheduled exports run at 11:00 daily, 11:15 weekly on Monday, and 11:30 monthly.
* Import jobs run on the `imports` queue.

## Related App Areas

* `app/Jobs/ImportCreditorProfilesJob.php`
* `app/Console/Commands/RunEcoMailHubCampaignCommand.php`
* `app/Jobs/ProcessEcoMailHubCampaignCreditorProfilesJob.php`
* `app/Console/Commands/DailyCRMScheduleExportCommand.php`
* `app/Console/Commands/WeeklyCRMScheduleExportCommand.php`
* `app/Console/Commands/MonthlyCRMScheduleExportCommand.php`
* `app/Jobs/SendCRMScheduleExportEmailJob.php`
