# Events in IMS2 — business logic and user guide

For users who configure and work with tracking rules (Tools → Events).
Explains how the system works at the business-logic level, not how to
click buttons.

---

## 1. What this actually is

Events is a mechanism that **watches** stock and operations by itself and
reports when something needs attention — no need to manually check stock
levels every day. Two parts:

- **Rule** (Rules tab) — what exactly to track and how often to
  check. Configured once.
- **Message** (Events tab + the main-screen panel) — the result
  of a rule firing. Appears by itself once the condition is met.

---

## 2. What a rule can track

A rule checks one of two things:

### 2.1. Stock below a threshold (the main scenario)

You specify an item and a minimum threshold (**Min Stock Threshold**) —
the system compares current stock against the threshold on every check.

- If stock falls **below** the threshold — a "shortage" message opens.
- If stock rises **above** the threshold again (a new lot arrived, stock
  was moved in) — the message **closes itself**, no action needed. The
  problem is considered resolved once the stock is sufficient again.
- Repeated messages for the same unresolved case are not spawned — while
  the problem persists, a single message stays open (its current stock
  value just gets refreshed), not a dozen identical ones.

**Warehouse** — an optional refining parameter. If not specified, the
threshold is checked against the **combined stock across all
warehouses**. If a specific warehouse is specified, only that one is
checked.

This matters if you have several warehouses with different roles (e.g. a
main purchasing warehouse and a working location/kitchen/shop floor where
the needed quantity is moved to). In that case the combined total can be
misleading: the item is "sufficient overall" while the place it's
actually consumed from is already empty. Specify a particular warehouse
if consumption happens from that warehouse specifically, not from
anywhere.

### 2.2. Whether an operation happened within a period

You specify company/item/operation type/order number (any combination) —
the system checks whether at least one matching operation happened during
the tracked period. Used less often, to check "did we forget to make a
delivery/payment."

---

## 3. One-time or recurring check

- **One-time** (Period field empty) — checked once, then the rule
  deactivates itself.
- **Recurring** (Period in the format `W;2;6` or `M;1;15`) — checked
  regularly, the next date is recalculated automatically after each
  check:
  - `W;2;6` — weekly, on the given days of the week (1=Sunday, 2=Monday
    ... 6=Friday — Delphi-compatible numbering, 1-based starting on
    Sunday).
  - `M;1;15` — monthly, on the given days of the month (the 1st and 15th).

For "stock below threshold" rules the period is effectively irrelevant —
they're checked **on every login**, continuously, until closed manually
(see §5). The period format is primarily meaningful for the §2.2
scenario.

---

## 4. Where the result shows up

- **The main-screen panel** (left side) — shows **only** open "stock below
  threshold" messages. Nothing else — not operations, not orders, so it
  doesn't distract from what matters most.
- **Tools → Events → the Events tab** — the full log of all messages (open
  and closed, both types), with company/item filters.

---

## 5. How to close a message

**There is no "dismiss" button on the main-screen panel.** This is a
deliberate decision: only whoever configured the rule and understands
what's happening should be able to close a problem — not any user with a
single click.

The only way to close a message manually:

1. Tools → Events → the **Rules** tab.
2. Select the rule.
3. **Close Rule** button — deactivates the rule and closes all its open
   messages at the same time.

If the problem was real and was resolved (stock arrived, stock was moved
in) — the message closes **by itself**, no manual step needed (see §2.1).
Manual closing is for "false alarm" cases or when a rule is no longer
relevant (e.g. an item was discontinued).

**Delete Rule** is a different action — it fully removes the rule from the
reference table (not just closes it). Use it if a rule was created by
mistake or will never be needed again.
