# `Deputy.Sales`
[🔗](https://github.com/sgerrand/ex_deputy/blob/v0.5.3/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

    client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    metrics = %{
      data: [
        %{
          timestamp: 1660272300,
          area: 2,
          type: "Sales",
          reference: "API-Sales-Entry-1660272300",
          value: 100.30,
          employee: 1,
          location: 1
        }
      ]
    }
    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(),
  %{optional(atom() | String.t()) =&gt; String.t()} | keyword()
) ::
  {:ok, [map()]} | {:error, Deputy.Error.t()}
```

Retrieve sales data.

## Parameters

- `client`: A Deputy client.
- `params`: A map (or keyword list) of query parameters.

## Query parameters

Every value must be a `String.t()` — the Deputy API rejects requests
where numeric IDs or timestamps are sent as JSON numbers rather than
serialised strings.

- `areas` (`String.t()`): Comma-separated list of area IDs, e.g. `"1,2,3"`.
- `types` (`String.t()`): Comma-separated list of metric types, e.g. `"Sales"` or `"Sales,Footfall"`.
- `start` (`String.t()`): Unix timestamp for the inclusive start of the window, e.g. `"1626203567"`.
- `end` (`String.t()`): Unix timestamp for the inclusive end of the window, e.g. `"1657775576"`.

## Examples

    client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
    params = %{
      areas: "1",
      types: "Sales",
      start: "1626203567",
      end: "1657775576"
    }
    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*
