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

# Advance vacations (Adelanto)

> Learn how employees can borrow days from a future vacation period when their current allocation is exhausted, and how this affects their balance.

**Advance vacations** (adelanto de vacaciones) allow an employee to borrow days from the period they have not yet earned. This is useful when an employee has used all 30 days in their current period but still needs time off before a new period opens.

## How advance days are earned

The number of advance days an employee can request is not fixed — it grows over the course of the active period. The system accrues **2.5 days per completed calendar month** elapsed since `fechaInicioAnio`.

```
advance days available = completed months since period start × 2.5
maximum = 30 days
```

This calculation is performed by `calcularDiasAdelantoDisponiblesEnPeriodo` in `vacationUtils.ts`. The sidebar in the **Vacation Scheduling** module shows the current accrued balance, how many advance days have already been used, and how many remain.

<Info>
  An employee 4 months into a period has accrued 10 advance days (4 × 2.5). An employee 12 months in has the maximum of 30.
</Info>

## How to request an advance

The **Adelanto de Vacaciones** card appears in the right-hand sidebar of the scheduling module whenever an employee is selected. It is rendered by the `AdelantoVacaciones` component.

<Steps>
  <Step title="Open the scheduling module">
    Navigate to **Vacation Scheduling** and select the employee from the dropdown.
  </Step>

  <Step title="Review the advance balance">
    The **Adelanto de Vacaciones** card shows three numbers: days available (accrued this period), days already used, and days remaining to borrow.
  </Step>

  <Step title="Enter the number of days">
    Type the number of days you want to advance in the input field. The maximum is the employee's remaining advance balance for the current month.
  </Step>

  <Step title="Click Solicitar Adelanto">
    The system adds the requested days directly to the employee's block day balance. No separate vacation range is created at this step — the days simply become available in the block pool to be scheduled normally.
  </Step>
</Steps>

## What changes on the schedule

When an advance is requested, three fields on the `CronogramaVacaciones` record are updated immediately:

| Field                   | Change                                                                              |
| ----------------------- | ----------------------------------------------------------------------------------- |
| `diasAdelanto`          | Increases by the number of days advanced                                            |
| `diasTotales`           | Increases beyond the standard 30 (e.g., 30 + 5 = 35)                                |
| `diasBloqueDisponibles` | Increases by the same amount, making the days available to schedule as block ranges |

The HR administrator can then schedule the advance days as normal block ranges in the Vacation Scheduling module. Ranges created after an advance may carry `esAdelanto: true` to distinguish them from standard ranges.

## Removing an advance range

If you delete a range that was created using advance days (`esAdelanto: true`), the system reverses the advance:

* `diasAdelanto` decreases by the number of days in that range (minimum 0).
* `diasTotales` decreases back toward 30. If `diasAdelanto` reaches 0, `diasTotales` is reset to exactly 30.
* The block day balance adjusts accordingly.

This rollback logic runs inside `handleEliminarRango` in `RegistroVacaciones.tsx`.

<Warning>
  Advance days are borrowed from the **next** period. When the employee's new vacation period opens, the advanced days will already be considered used. Plan advances carefully — an employee who borrows 10 days in year one will start year two with only 20 available days until those are replenished by the accrual formula.
</Warning>

## Use case

An employee's `"2025-2026"` period runs from 1 June 2025 to 31 May 2026. By November 2025 they have used all 30 days. They need 5 additional days off in December.

By November, the employee has been in the period for 5 months, accruing **12.5 advance days** (5 × 2.5). They request a 5-day advance. The system:

1. Sets `diasAdelanto` to 5.
2. Sets `diasTotales` to 35.
3. Increases `diasBloqueDisponibles` by 5.

The HR administrator can then schedule a 5-day block range in December marked with `esAdelanto: true`. When the `"2026-2027"` period opens, those 5 days will be reflected in the new period's starting balance.
