Skip to content
Open
Changes from all commits
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
47 changes: 47 additions & 0 deletions Care/Inventory/inventory_report_pallium.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

# Inventory Report

> Per-location, per-batch inventory snapshot with purchase value and expiry flagging

## Purpose

Returns a full inventory snapshot with one row per inventory item. Each row shows the stock count, batch number, expiration date, unit purchase price, total purchase value (`stock_count × purchase_price`), and an `expiry_flag` that buckets each batch as **Expired**, **Critical (≤1 month)**, **Warning (≤3 months)**, or normal.

---

## Query

```sql
SELECT
fl.name AS location_name,
pk.name AS stock_name,
TO_CHAR(p.expiration_date, 'DD/MM/YYYY') AS expiration_date,
p.purchase_price,
ii.net_content * p.purchase_price AS total_purchase,
p.batch ->> 'lot_number' AS batch_number,
CASE
WHEN p.expiration_date <= CURRENT_DATE THEN 'Expired'
WHEN p.expiration_date <= CURRENT_DATE + INTERVAL '1 month' THEN 'Critical - Expires in 1 month'
WHEN p.expiration_date <= CURRENT_DATE + INTERVAL '3 months' THEN 'Warning - Expires in 3 months'
ELSE ''
Comment thread
sonzsara marked this conversation as resolved.
END AS expiry_flag,
ii.net_content AS stock_count
FROM emr_productknowledge pk
JOIN emr_product p
ON p.product_knowledge_id = pk.id
JOIN emr_inventoryitem ii
ON ii.product_id = p.id
JOIN emr_facilitylocation fl
ON ii.location_id = fl.id
WHERE fl.deleted = FALSE
Comment thread
sonzsara marked this conversation as resolved.
ORDER BY
fl.name,
pk.name,
p.expiration_date;
```


## Notes
- Results are ordered by location, followed by stock name and expiry

*Last updated: 2026-06-29*