Deputy.Employees (Deputy v0.4.0)

Copy Markdown View Source

Functions for interacting with employees in Deputy.

Summary

Functions

Post a journal entry for an employee.

Same as add_journal/2 but raises on error.

Add leave for an employee.

Same as add_leave/2 but raises on error.

Add a location to an employee.

Add unavailability for an employee.

Add a new employee.

Same as create/2 but raises on error.

Delete an employee's account in Deputy.

Same as delete/2 but raises on error.

Get employee by ID.

Same as get/2 but raises on error.

Get agreed hours for an employee.

Same as get_agreed_hours/2 but raises on error.

Get an employee's leave.

Same as get_leave/2 but raises on error.

Get an employee's current shift information.

Same as get_shift_info/2 but raises on error.

Get unavailability details for an employee.

Invite an employee to Deputy.

Same as invite/2 but raises on error.

Get all employees.

Same as list/1 but raises on error.

Reactivate a terminated employee.

Same as reactivate/2 but raises on error.

Remove a location from an employee.

Set award for an employee.

Same as set_award/3 but raises on error.

Terminate an employee.

Same as terminate/2 but raises on error.

Update an existing employee.

Same as update/3 but raises on error.

Functions

add_journal(client, attrs)

@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!(client, attrs)

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

Same as add_journal/2 but raises on error.

add_leave(client, attrs)

@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!(client, attrs)

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

Same as add_leave/2 but raises on error.

add_location(client, employee_id, company_id)

@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!(client, employee_id, company_id)

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

Same as add_location/3 but raises on error.

add_unavailability(client, attrs)

@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!(client, attrs)

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

Same as add_unavailability/2 but raises on error.

create(client, attrs)

@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!(client, attrs)

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

Same as create/2 but raises on error.

delete(client, id)

@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!(client, id)

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

Same as delete/2 but raises on error.

get(client, id)

@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!(client, id)

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

Same as get/2 but raises on error.

get_agreed_hours(client, id)

@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!(client, id)

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

Same as get_agreed_hours/2 but raises on error.

get_leave(client, id)

@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!(client, id)

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

Same as get_leave/2 but raises on error.

get_shift_info(client, id)

@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!(client, id)

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

Same as get_shift_info/2 but raises on error.

get_unavailability(client, id)

@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!(client, id)

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

Same as get_unavailability/2 but raises on error.

invite(client, id)

@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!(client, id)

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

Same as invite/2 but raises on error.

list(client)

@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!(client)

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

Same as list/1 but raises on error.

reactivate(client, id)

@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!(client, id)

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

Same as reactivate/2 but raises on error.

remove_location(client, employee_id, company_id)

@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!(client, employee_id, company_id)

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

Same as remove_location/3 but raises on error.

set_award(client, id, attrs)

@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!(client, id, attrs)

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

Same as set_award/3 but raises on error.

terminate(client, id)

@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!(client, id)

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

Same as terminate/2 but raises on error.

update(client, id, attrs)

@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!(client, id, attrs)

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

Same as update/3 but raises on error.