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

Functions for interacting with sales metrics in Deputy.

# `add_metrics`

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

Add a sale to sales metrics.

## Parameters

- `client`: A Deputy client.
- `metrics`: A map containing sales data.

## Metrics parameters

- `data`: Array of sale objects with the following fields:
  - `timestamp`: Unix timestamp of the sale.
  - `area`: ID of the area where the sale occurred.
  - `type`: Type of metric (e.g., "Sales").
  - `reference`: Reference ID for the sale.
  - `value`: Sale amount.
  - `employee`: Optional. ID of the employee who made the sale.
  - `location`: ID of the location where the sale occurred.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> metrics = %{
    ...>   data: [
    ...>     %{
    ...>       timestamp: 1660272300,
    ...>       area: 2,
    ...>       type: "Sales",
    ...>       reference: "API-Sales-Entry-1660272300",
    ...>       value: 100.30,
    ...>       employee: 1,
    ...>       location: 1
    ...>     }
    ...>   ]
    ...> }
    iex> Deputy.Sales.add_metrics(client, metrics)
    {:ok, %{"success" => true}}

# `add_metrics!`

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

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

# `get_metrics`

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

Retrieve sales data.

## Parameters

- `client`: A Deputy client.
- `params`: A map containing query parameters.

## Query parameters

- `areas`: Comma-separated list of area IDs.
- `types`: Comma-separated list of metric types (e.g., "Sales").
- `start`: Unix timestamp for the start date.
- `end`: Unix timestamp for the end date.

## Examples

    iex> client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    iex> params = %{
    ...>   areas: "1",
    ...>   types: "Sales",
    ...>   start: "1626203567",
    ...>   end: "1657775576"
    ...> }
    iex> Deputy.Sales.get_metrics(client, params)
    {:ok, [%{"timestamp" => 1626203600, "area" => 1, "type" => "Sales", "value" => 100.30}]}

# `get_metrics!`

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

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

---

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