> ## 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.

# Calendar Sync Jobs

> Jane's failed installment is moved to the end of the plan after an auto-skip.

## Real-World Example

Jane's failed installment is moved to the end of the plan after an auto-skip. The payment schedule changes in the portal first, then calendar sync jobs update or delete the old external calendar event and create the new one when live sync is enabled.

## Visual Flow

```mermaid placement="top-right" actions={true} theme={"system"}
flowchart TD
    A["Payment schedule changes in background"] --> B["Portal checks calendar sync preference"]
    B --> C{"Live sync enabled?"}
    C -->|Yes| D["Calendar job updates external event"]
    C -->|No| E["No external calendar change is sent"]
    D --> F["Google or Microsoft Calendar matches portal schedule"]
    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,B,D,E system;
    class C decision;
    class F outcome;
    linkStyle default stroke:#94A3B8,stroke-width:2px;
```

## How It Should Work

* It should keep external calendar events aligned when payment jobs move, skip, delete, or complete scheduled transactions.
* It should run after the portal schedule is updated.
* It should handle provider errors without corrupting payment state.

## How It Should Not Work

* It should not make external calendars the source of truth for payment schedules.
* It should not update external events when the consumer has not enabled live sync.
* It should not create duplicate events for schedule transactions already synced.

## Developer Notes

* Calendar sync is touched by manual schedule changes and background installment jobs.
* Create, update, amount update, and delete jobs should stay idempotent.

## Related App Areas

* `app/Jobs/CreateCalendarEvents.php`
* `app/Jobs/UpdateCalendarEvents.php`
* `app/Jobs/UpdateCalendarEventAmount.php`
* `app/Jobs/DeleteCalendarEvents.php`
* `app/Jobs/SkipScheduleTransactionJob.php`
* `app/Console/Commands/RestartPaymentPlanCommand.php`
