# `Deputy.Employees`
[🔗](https://github.com/sgerrand/ex_deputy/blob/v0.4.0/lib/deputy/employees.ex#L1)

Functions for interacting with employees in Deputy.

# `add_journal`

```elixir
@spec add_journal(Deputy.t(), map()) :: {:ok, map()} | {:error, Deputy.Error.t()}
```

Post a journal entry for an employee.

## Parameters

- `client`: A Deputy client.
- `attrs`: A map containing the journal details.

## Journal parameters

- `strComment`: The journal comment.
- `intEmployeeId`: ID of the employee.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Employees.add_journal(client, %{strComment: "Employee performed well today", intEmployeeId: 1})
    {:ok, %{"Id" => 123}}

# `add_journal!`

```elixir
@spec add_journal!(Deputy.t(), map()) :: map()
```

Same as `add_journal/2` but raises on error.

# `add_leave`

```elixir
@spec add_leave(Deputy.t(), map()) :: {:ok, map()} | {:error, Deputy.Error.t()}
```

Add leave for an employee.

## Parameters

- `client`: A Deputy client.
- `attrs`: A map containing the leave details.

## Leave parameters

- `Status`: Status code for the leave (e.g., 1 for approved).
- `Employee`: ID of the employee.
- `DateStart`: Start date in format "YYYY/MM/DD".
- `DateEnd`: End date in format "YYYY/MM/DD".
- `ApprovalComment`: Optional. Comment for the leave approval.
- `ActionOverlappingRosters`: How to handle overlapping rosters (e.g., 0 to keep).

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> attrs = %{
    ...>   Status: 1,
    ...>   Employee: 1,
    ...>   DateStart: "2023/01/01",
    ...>   DateEnd: "2023/01/05",
    ...>   ApprovalComment: "Vacation",
    ...>   ActionOverlappingRosters: 0
    ...> }
    iex> Deputy.Employees.add_leave(client, attrs)
    {:ok, %{"Id" => 123}}

# `add_leave!`

```elixir
@spec add_leave!(Deputy.t(), map()) :: map()
```

Same as `add_leave/2` but raises on error.

# `add_location`

```elixir
@spec add_location(Deputy.t(), integer(), integer()) ::
  {:ok, map()} | {:error, Deputy.Error.t()}
```

Add a location to an employee.

## Parameters

- `client`: A Deputy client.
- `employee_id`: The ID of the employee.
- `company_id`: The ID of the location/company to associate with the employee.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Employees.add_location(client, 1, 2)
    {:ok, %{"success" => true}}

# `add_location!`

```elixir
@spec add_location!(Deputy.t(), integer(), integer()) :: map()
```

Same as `add_location/3` but raises on error.

# `add_unavailability`

```elixir
@spec add_unavailability(Deputy.t(), map()) ::
  {:ok, map()} | {:error, Deputy.Error.t()}
```

Add unavailability for an employee.

## Parameters

- `client`: A Deputy client.
- `attrs`: A map containing the unavailability details.

## Unavailability parameters

- `employee`: ID of the employee.
- `start`: Map with timestamp for start time.
- `end`: Map with timestamp for end time.
- `strComment`: Optional. Comment for the unavailability.
- `recurrence`: Optional. Map with recurrence pattern.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> attrs = %{
    ...>   employee: 1,
    ...>   start: %{timestamp: 1657001675},
    ...>   end: %{timestamp: 1657001676},
    ...>   strComment: "Weekly appointment",
    ...>   recurrence: %{FREQ: "WEEKLY", INTERVAL: 1, BYDAY: "MO"}
    ...> }
    iex> Deputy.Employees.add_unavailability(client, attrs)
    {:ok, %{"Id" => 123}}

# `add_unavailability!`

```elixir
@spec add_unavailability!(Deputy.t(), map()) :: map()
```

Same as `add_unavailability/2` but raises on error.

# `create`

```elixir
@spec create(Deputy.t(), map()) :: {:ok, map()} | {:error, Deputy.Error.t()}
```

Add a new employee.

## Parameters

- `client`: A Deputy client.
- `attrs`: A map containing the new employee details.

## Employee parameters

- `strFirstName`: Employee's first name.
- `strLastName`: Employee's last name.
- `intCompanyId`: ID of the company/location where the employee works.
- `intGender`: Integer representing gender (e.g., 1 for male, 2 for female).
- `strCountryCode`: Country code (e.g., "US").
- `strDob`: Date of birth in format "YYYY-MM-DD".
- `strStartDate`: Employment start date in format "YYYY-MM-DD".
- `strMobilePhone`: Mobile phone number.
- `strPayrollId`: Optional. Payroll ID.
- `fltWeekDayRate`: Optional. Weekday pay rate.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> attrs = %{
    ...>   strFirstName: "John",
    ...>   strLastName: "Doe",
    ...>   intCompanyId: 1,
    ...>   intGender: 1,
    ...>   strCountryCode: "US",
    ...>   strDob: "1980-01-01",
    ...>   strStartDate: "2023-01-01",
    ...>   strMobilePhone: "5551234567"
    ...> }
    iex> Deputy.Employees.create(client, attrs)
    {:ok, %{"Id" => 123}}

# `create!`

```elixir
@spec create!(Deputy.t(), map()) :: map()
```

Same as `create/2` but raises on error.

# `delete`

```elixir
@spec delete(Deputy.t(), integer()) :: {:ok, map()} | {:error, Deputy.Error.t()}
```

Delete an employee's account in Deputy.

## Parameters

- `client`: A Deputy client.
- `id`: The ID of the employee to delete.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Employees.delete(client, 1)
    {:ok, %{"success" => true}}

# `delete!`

```elixir
@spec delete!(Deputy.t(), integer()) :: map()
```

Same as `delete/2` but raises on error.

# `get`

```elixir
@spec get(Deputy.t(), integer()) :: {:ok, map()} | {:error, Deputy.Error.t()}
```

Get employee by ID.

## Parameters

- `client`: A Deputy client.
- `id`: The ID of the employee to retrieve.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Employees.get(client, 1)
    {:ok, %{"Id" => 1, "FirstName" => "John", "LastName" => "Doe"}}

# `get!`

```elixir
@spec get!(Deputy.t(), integer()) :: map()
```

Same as `get/2` but raises on error.

# `get_agreed_hours`

```elixir
@spec get_agreed_hours(Deputy.t(), integer()) ::
  {:ok, map()} | {:error, Deputy.Error.t()}
```

Get agreed hours for an employee.

## Parameters

- `client`: A Deputy client.
- `id`: The ID of the employee.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Employees.get_agreed_hours(client, 1)
    {:ok, %{"AgreedHours" => 40.0}}

# `get_agreed_hours!`

```elixir
@spec get_agreed_hours!(Deputy.t(), integer()) :: map()
```

Same as `get_agreed_hours/2` but raises on error.

# `get_leave`

```elixir
@spec get_leave(Deputy.t(), integer()) :: {:ok, [map()]} | {:error, Deputy.Error.t()}
```

Get an employee's leave.

## Parameters

- `client`: A Deputy client.
- `id`: The ID of the employee.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Employees.get_leave(client, 1)
    {:ok, [%{"Id" => 123, "DateStart" => "2023-01-01", "DateEnd" => "2023-01-05"}]}

# `get_leave!`

```elixir
@spec get_leave!(Deputy.t(), integer()) :: [map()]
```

Same as `get_leave/2` but raises on error.

# `get_shift_info`

```elixir
@spec get_shift_info(Deputy.t(), integer()) ::
  {:ok, map()} | {:error, Deputy.Error.t()}
```

Get an employee's current shift information.

## Parameters

- `client`: A Deputy client.
- `id`: The ID of the employee.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Employees.get_shift_info(client, 1)
    {:ok, %{"Status" => "On Shift", "RosterID" => 123}}

# `get_shift_info!`

```elixir
@spec get_shift_info!(Deputy.t(), integer()) :: map()
```

Same as `get_shift_info/2` but raises on error.

# `get_unavailability`

```elixir
@spec get_unavailability(Deputy.t(), integer()) ::
  {:ok, [map()]} | {:error, Deputy.Error.t()}
```

Get unavailability details for an employee.

## Parameters

- `client`: A Deputy client.
- `id`: The ID of the employee.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Employees.get_unavailability(client, 1)
    {:ok, [%{"Id" => 123, "Start" => %{"timestamp" => 1657001675}, "End" => %{"timestamp" => 1657001676}}]}

# `get_unavailability!`

```elixir
@spec get_unavailability!(Deputy.t(), integer()) :: [map()]
```

Same as `get_unavailability/2` but raises on error.

# `invite`

```elixir
@spec invite(Deputy.t(), integer()) :: {:ok, map()} | {:error, Deputy.Error.t()}
```

Invite an employee to Deputy.

## Parameters

- `client`: A Deputy client.
- `id`: The ID of the employee to invite.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Employees.invite(client, 1)
    {:ok, %{"success" => true}}

# `invite!`

```elixir
@spec invite!(Deputy.t(), integer()) :: map()
```

Same as `invite/2` but raises on error.

# `list`

```elixir
@spec list(Deputy.t()) :: {:ok, [map()]} | {:error, Deputy.Error.t()}
```

Get all employees.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Employees.list(client)
    {:ok, [%{"Id" => 1, "FirstName" => "John", "LastName" => "Doe"}]}

# `list!`

```elixir
@spec list!(Deputy.t()) :: [map()]
```

Same as `list/1` but raises on error.

# `reactivate`

```elixir
@spec reactivate(Deputy.t(), integer()) :: {:ok, map()} | {:error, Deputy.Error.t()}
```

Reactivate a terminated employee.

## Parameters

- `client`: A Deputy client.
- `id`: The ID of the employee to reactivate.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Employees.reactivate(client, 1)
    {:ok, %{"success" => true}}

# `reactivate!`

```elixir
@spec reactivate!(Deputy.t(), integer()) :: map()
```

Same as `reactivate/2` but raises on error.

# `remove_location`

```elixir
@spec remove_location(Deputy.t(), integer(), integer()) ::
  {:ok, map()} | {:error, Deputy.Error.t()}
```

Remove a location from an employee.

## Parameters

- `client`: A Deputy client.
- `employee_id`: The ID of the employee.
- `company_id`: The ID of the location/company to remove from the employee.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Employees.remove_location(client, 1, 2)
    {:ok, %{"success" => true}}

# `remove_location!`

```elixir
@spec remove_location!(Deputy.t(), integer(), integer()) :: map()
```

Same as `remove_location/3` but raises on error.

# `set_award`

```elixir
@spec set_award(Deputy.t(), integer(), map()) ::
  {:ok, map()} | {:error, Deputy.Error.t()}
```

Set award for an employee.

## Parameters

- `client`: A Deputy client.
- `id`: The ID of the employee.
- `attrs`: A map containing the award details.

## Award parameters

- `strCountryCode`: Country code (e.g., "au").
- `strAwardCode`: Award code.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Employees.set_award(client, 1, %{strCountryCode: "au", strAwardCode: "casual-2021-11-01-aea-2"})
    {:ok, %{"success" => true}}

# `set_award!`

```elixir
@spec set_award!(Deputy.t(), integer(), map()) :: map()
```

Same as `set_award/3` but raises on error.

# `terminate`

```elixir
@spec terminate(Deputy.t(), integer()) :: {:ok, map()} | {:error, Deputy.Error.t()}
```

Terminate an employee.

## Parameters

- `client`: A Deputy client.
- `id`: The ID of the employee to terminate.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Employees.terminate(client, 1)
    {:ok, %{"success" => true}}

# `terminate!`

```elixir
@spec terminate!(Deputy.t(), integer()) :: map()
```

Same as `terminate/2` but raises on error.

# `update`

```elixir
@spec update(Deputy.t(), integer(), map()) ::
  {:ok, map()} | {:error, Deputy.Error.t()}
```

Update an existing employee.

## Parameters

- `client`: A Deputy client.
- `id`: The ID of the employee to update.
- `attrs`: A map containing the fields to update.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> Deputy.Employees.update(client, 1, %{Phone: "5559876543"})
    {:ok, %{"success" => true}}

# `update!`

```elixir
@spec update!(Deputy.t(), integer(), map()) :: map()
```

Same as `update/3` but raises on error.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
