-
Notifications
You must be signed in to change notification settings - Fork 1
Documentation on Internal stock transfer report #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sonzsara
wants to merge
1
commit into
main
Choose a base branch
from
ENG-637
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
|
|
||
| # Internal Stock Transfer Report | ||
|
|
||
| > Line-level report of internal stock transfers between facility locations with batch, expiry, and quantity | ||
| ## Purpose | ||
|
|
||
| Lists supply deliveries at Pallium that move stock **between two facility locations** (origin → destination). Each row shows the supply date, origin and destination locations, the product (with batch / lot number and expiry), and the quantity transferred. | ||
|
|
||
| ## Parameters | ||
|
|
||
| | Parameter | Type | Description | Example | | ||
| |-----------|------|-------------|---------| | ||
| | `date` | DATE / range | Metabase date filter (typically bound to `sd.created_date`) | `'2026-06-01'` | | ||
| | `stock_name` | TEXT | Filter by product / stock name (exact match on `emr_productknowledge.name`) | `'Paracetamol'` | | ||
|
|
||
| --- | ||
|
|
||
| ## Query | ||
|
|
||
| ```sql | ||
| SELECT | ||
| DATE(sd.created_date) AS supply_date, | ||
| fl_origin.name AS origin_location, | ||
| fl_dest.name AS destination_location, | ||
| p.batch ->> 'lot_number' AS lot_number, | ||
| p.expiration_date, | ||
| pk.name AS product_name, | ||
| sd.supplied_item_quantity AS quantity_delivered | ||
| FROM emr_supplydelivery sd | ||
| JOIN emr_inventoryitem ii | ||
| ON sd.supplied_inventory_item_id = ii.id | ||
| JOIN emr_product p | ||
| ON ii.product_id = p.id | ||
| JOIN emr_productknowledge pk | ||
| ON p.product_knowledge_id = pk.id | ||
| JOIN emr_deliveryorder d | ||
| ON sd.order_id = d.id | ||
| JOIN emr_facilitylocation fl_origin | ||
| ON d.origin_id = fl_origin.id | ||
| JOIN emr_facilitylocation fl_dest | ||
| ON d.destination_id = fl_dest.id | ||
| WHERE sd.status NOT IN ('entered_in_error','abandoned') | ||
| --[[AND {{date}}]] | ||
| --[[AND pk.name = {{stock_name}}]] | ||
| ORDER BY supply_date DESC; | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| - **Internal transfer scope:** Joining `emr_deliveryorder` on both `origin_id` and `destination_id` to `emr_facilitylocation` (via `fl_origin` and `fl_dest`) means only deliveries that have both a source and destination facility location are returned — i.e. internal transfers. | ||
| - Results are ordered by most recent `supply_date` first. | ||
|
|
||
| *Last updated: 2026-06-29* | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inventory_item join should be unnecessary/we can go from supply_delivery to product for internal, but do check.