# Sales

Deals, pipelines, POS, and ecommerce


Deal pipelines, point-of-sale configuration and orders, and storefront ecommerce helpers.

Sales provides the deal pipeline (boards → pipelines → stages → deals with labels, checklists, watchers, and per-deal product/payment data), the POS configuration and order API used by the separate `posclient` plugin, and a small ecommerce module (wishlists, reviews, addresses, last-viewed items) exposed over HTTP routes and GraphQL. It registers with the platform through `meta/`: permissions, automations, notifications, the `sales:sales.deals` and `sales:pos.orders` segment definitions, `sales:deal` document generation, record references (including `excludeLoyaltyAmount`), and the `deal` property type.

`sales_api` contains the POS *configuration and order APIs*. `posclient_api` and the `posclient-front` app are the separately deployed storefront; they sync through this plugin's `/pos-init`, `/pos-sync-config`, and `/get-pos-token` routes ([`src/routes.ts`](https://github.com/erxes/erxes/blob/f91e8c6f4714c910a32c6b6e14fe085f6435c89e/backend/plugins/sales_api/src/routes.ts)) and the `pos.createOrUpdateOrders*` tRPC procedures ([`src/trpc/init-trpc.ts`](https://github.com/erxes/erxes/blob/f91e8c6f4714c910a32c6b6e14fe085f6435c89e/backend/plugins/sales_api/src/trpc/init-trpc.ts)).

For the product catalog itself, see [Products](https://erxes.io/docs/core-products); for the deployed POS storefront, see [POS Client](https://erxes.io/docs/app-pos-client).

## Enabling and ports

```dotenv
ENABLED_PLUGINS=sales
```

The entry maps to `sales_api` and `sales_ui`; dev scripts append `_api`/`_ui` to each name in `ENABLED_PLUGINS`.

| Project | Role | Dev port |
| --- | --- | --- |
| `sales_api` | Federated GraphQL subgraph + tRPC + POS/ecommerce HTTP routes; subscriptions enabled | `3305` |
| `sales_ui` | Module Federation remote | `3005` |

The API port is set in [`main.ts`](https://github.com/erxes/erxes/blob/f91e8c6f4714c910a32c6b6e14fe085f6435c89e/backend/plugins/sales_api/src/main.ts).

The POS storefront backend (`posclient_api`, port `3312`) and app (`apps/posclient-front`, dev port `7002`) are separate; see [Point of Sale](https://erxes.io/docs/sales-pos) and [POS Client](https://erxes.io/docs/app-pos-client).

## Module map

| Module | What it contains | Key collections | Guide |
| --- | --- | --- | --- |
| `modules/sales/` | Boards, pipelines, stages, deals, labels, checklists; segment fields, documents, references | `Deals`, `Pipelines`, `Stages`, `Boards` | [Deals & Pipelines](https://erxes.io/docs/sales-deals-pipelines) |
| `modules/pos/` | POS configs, orders, covers, slots, product groups; POS sync routes | `Pos`, `PosOrders`, `PosCovers`, `PosSlots` | [Point of Sale](https://erxes.io/docs/sales-pos) |
| `modules/ecommerce/` | Wishlists, product reviews, addresses, last-viewed items | `Wishlist`, `ProductReview`, `Address`, `LastViewedItem` | [Ecommerce](https://erxes.io/docs/sales-ecommerce) |
| `meta/` | permissions, automations, notifications, segments, documents, references, properties, beforeResolvers, afterProcess | platform extension points | this page and module pages |

Frontend `sales_ui` modules mirror this: `deals/` (boards, pipelines, deal detail, product/payment data), `payments/`, `pos/` (POS settings under `settings/sales/*`). `src/config.tsx` registers `sales/deals`, `sales/pos`, and `settings/sales/*` navigation.

## How it connects to Core

- **Properties**: `meta/properties.ts` declares the `deal` property type with its `systemFields`; pipeline `propertyIds` are validated against Core `sales:deal` fields over tRPC (`fields.find`).
- **Segments**: `meta/segments.ts` merges the `sales` and `pos` module definitions: `sales:sales.deals` and `sales:pos.orders` content types, `customer.deals`/`company.deals` relations backed by Core relation records, plus `evaluateFields`, `listSegmentMembers`, `countSegmentMembers`, and `applyMembership` producers. See [Properties, Tags & Segments](https://erxes.io/docs/core-properties-tags-segments).
- **Automations**: `meta/automations.ts` registers deal triggers/actions and the POS-order event trigger; see [Automations & Approvals](https://erxes.io/docs/core-automations-approvals).
- **Documents**: `meta/documents.ts` registers `sales:deal` for document templates; `documents.editorAttributes` and `deal.replaceContent` tRPC procedures provide the editor merge fields. See [Documents](https://erxes.io/docs/core-forms-documents).
- **Payments**: `meta.payments` callbacks apply paid transactions to `mobileAmount`/`mobileAmounts` on deals and forward POS-order payments to `posclient` over tRPC. Payment providers are part of the Enterprise Edition.
- **Import/export**: one export type, `sales:pos.posItems`, gated by `posItemsExportManage`.

## Configuration

Env vars the plugin reads directly:

| Variable | Purpose |
| --- | --- |
| `GET_CP_TOKEN` | Shared secret for `GET /get-pos-token`, which lists POS names and tokens for the client-portal flow |
| `ALLOW_OFFLINE_POS` | When truthy, lets `pos.create` keep `onServer` unset (offline-capable POS); otherwise new POS docs are forced `onServer` |
| `DOMAIN` | Base URL used to build deal/board links (`{DOMAIN}/deal/board?...`) |
| `TIMEZONE`, `NODE_ENV` | Timezone for date handling; production flag for the subscription bundle |

POS credentials live on the POS document itself (`token`, `adminIds`, `cashierIds`, `paymentIds`).

## Pages in this section

- [Deals & Pipelines](https://erxes.io/docs/sales-deals-pipelines): Boards, pipelines, stages, deals, labels, and checklists
- [Point of Sale](https://erxes.io/docs/sales-pos): POS configuration, orders, sync routes, and the posclient API
- [Ecommerce](https://erxes.io/docs/sales-ecommerce): Storefront helpers, carts, and order endpoints
- [POS Client](https://erxes.io/docs/app-pos-client): Offline-capable storefront and posclient API

