Skip to content

fix(pharmacy-report): show net consumption in Disposal Consumption Report (#21025) [ruhunu hotfix]#21034

Open
buddhika75 wants to merge 1 commit into
ruhunu-prodfrom
21025-consumption-report-return-sign-correction-ruhunu-hotfix
Open

fix(pharmacy-report): show net consumption in Disposal Consumption Report (#21025) [ruhunu hotfix]#21034
buddhika75 wants to merge 1 commit into
ruhunu-prodfrom
21025-consumption-report-return-sign-correction-ruhunu-hotfix

Conversation

@buddhika75
Copy link
Copy Markdown
Member

Summary

Hotfix to ruhunu-prod mirroring the fix in #21030 (against development). The bug was first reported on Ruhunu (#21025), so this is the production branch where it needs to land.

Issue #21025 reported the Disposal Consumption Report inflating quantity (8 issued + 8 returned shown as 16) and showing 0 for Purchase / Cost / Retail Value while Net Value looked correct. Root cause: billItem.qty is stored positive on both issue and return bills, while billItemFinanceDetails.valueAt*Rate / billFinanceDetails.total*Value use a stock-direction sign (negative on stock-out, positive on stock-back-in). Aggregations summed the two conventions raw, so qty over-counted and value columns cancelled.

This change normalises each row to consumption direction (issue +, return / cancel −) before aggregating; netTotal already carries the correct sign and is left alone. The byBill / byBillItem tables now expose per-row consumption-direction values on PharmacyRow so the on-screen rows and the footer total agree, and the PDF export reads the same fields.

Data is uniformly in the canonical convention (verified against ruhunu prod, 12.8 K issue rows / 160 return rows all in the expected sign). No data backfill required — the fix is purely reporting logic.

Test plan

  • Open Consumption Report on ruhunu-prod, run as Summary across a date range that includes both issues and returns; confirm Purchase / Cost / Retail aggregate to net consumption (not ~0).
  • By Bill Item filtered to TRIMETHOPRIM-SULFAMETHOXAZOLE 1.25/23.75 µg (CT0052), period 2026-02-20 → 2026-03-30: net qty should show 7 (was 19 raw); return rows display negative qty/value; footer matches row sum.
  • By Bill: same at bill granularity for R/DIS/RHD/LBK/26/000079 / DIS/ML/RHD/26/000141, DIS/LBK/RHD/26/000249, R/DIS/RHD/LBK/26/000111 / DIS/ML/RHD/26/000161.
  • PDF / Excel byBill export values match the on-screen rows.

Refs #21025
Refs #21030
Refs #21032 (tracking issue for the wider sign-convention normalisation)

🤖 Generated with Claude Code

…port

The Disposal Consumption Report mixed two sign conventions that coexist on
disposal-issue bills: `billItem.qty` is stored positive on both issue and
return bills, while `billItemFinanceDetails.valueAt*Rate` (and the bill-level
`billFinanceDetails.total*Value`) use a stock-direction sign — negative when
stock leaves, positive when it comes back. See
`DataAdministrationController.isFinanceValueNegative` for the canonical rule.

The byBill, byBillItem, and summary aggregations summed those fields raw, so:
- quantity columns counted issued and returned units both positive, inflating
  totals (e.g. 8 issued + 8 returned showed as 16 instead of 0);
- purchase/cost/retail summary columns netted to ~0 because issue and return
  rows cancelled, even when net consumption was non-zero, while the netTotal
  column (already signed correctly) was the only column that looked right.

Translate each row to consumption direction (issue +, return/cancel −) before
aggregating: negate the stored valueAt*Rate (its sign is opposite to
consumption) and negate qty on return/cancel rows. netTotal already carries
the right sign and is left alone. The byBill and byBillItem table now expose
the per-row consumption-direction values on PharmacyRow so totals and rows
agree, and the PDF export reads the same fields.

Closes #21025

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d851484c-72e0-40a5-bcbb-4be5b6326b1c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 21025-consumption-report-return-sign-correction-ruhunu-hotfix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8bb498ce4f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

double rowPurchase = valueAtPurchase != null ? valueSign * valueAtPurchase.doubleValue() : 0.0;
double rowCost = valueAtCost != null ? valueSign * valueAtCost.doubleValue() : 0.0;
double rowRetail = valueAtRetail != null ? valueSign * valueAtRetail.doubleValue() : 0.0;
double rowQty = qtySign * (row.getBillItem().getQty() != null ? row.getBillItem().getQty() : 0.0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve quantities when finance details are absent

When a disposal bill item has no BillItemFinanceDetails (the query above does not exclude those rows), this calculation is skipped because the whole block is guarded by row.getBillItem().getBillItemFinanceDetails() != null. Since the XHTML now displays i.consumptionQty instead of i.billItem.qty, those legacy/partial rows show a quantity of 0 even though the bill item still has a quantity; compute consumptionQty outside the finance-details guard so only the value columns default to zero.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant