Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Care/Operations/stock_in_air_ssmm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

# Stock in Air - SSMM

> In-transit stock deliveries (in-progress) with product, quantity, route, and creator details

## Purpose

Lists stock deliveries that are currently `in_progress` ("stock in air") at SSMM, showing what product is moving, quantity, delivery/order status, movement date, origin and destination locations, and the user who created the delivery record.
Comment thread
sonzsara marked this conversation as resolved.
Outdated

## Parameters

| Parameter | Type | Description | Example |
|-----------|------|-------------|---------|
| `date` | DATE / range | Metabase date filter (typically bound to `esd.created_date`) | `'2026-08-01'` |

---

## Query

```sql
SELECT
epk.name AS product_name,
esd.supplied_item_quantity AS supplied_qty,
esd.status AS delivery_status,
edo.status AS order_status,
esd.created_date AS delivery_date,
origin.name AS origin,
destination.name AS destination,
CONCAT(uu.first_name, ' ', uu.last_name) AS delivery_created_by
FROM emr_supplydelivery esd
JOIN emr_deliveryorder edo
ON esd.order_id = edo.id
JOIN emr_inventoryitem eii
ON esd.supplied_inventory_item_id = eii.id
JOIN emr_product ep
ON eii.product_id = ep.id
JOIN emr_productknowledge epk
ON ep.product_knowledge_id = epk.id
JOIN emr_facilitylocation origin
Comment thread
sonzsara marked this conversation as resolved.
ON origin.id = edo.origin_id
AND origin.deleted = FALSE

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirm this with product

JOIN emr_facilitylocation destination
ON destination.id = edo.destination_id
AND destination.deleted = FALSE
LEFT JOIN users_user uu
ON uu.id = esd.created_by_id
WHERE edo.origin_id IS NOT NULL
AND esd.status = 'in_progress'
--[[AND {{date}}]]
Comment thread
sonzsara marked this conversation as resolved.
Outdated
ORDER BY epk.name;
```

## Notes

- **"Stock in air" definition:** This query treats any supply delivery with `esd.status = 'in_progress'` as in-transit stock.
- **Metabase filter:** `[[AND {{date}}]]` is a field filter — bind it to `esd.created_date`.
- Results are ordered alphabetically by `product_name`.

*Last updated: 2026-08-13*