Skip to content

Conversation

@rithviknishad
Copy link
Member

@rithviknishad rithviknishad commented Feb 2, 2026

image

Summary by CodeRabbit

  • New Features
    • Enhanced delivery order view with a totals summary card displaying total items count, total quantity, and the aggregated monetary value across all delivery items.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 2, 2026

Walkthrough

This PR adds delivery order totals display functionality. It introduces translation keys for item and quantity totals, implements a new calculation utility for delivery totals using Decimal arithmetic, and renders aggregated totals in a CardFooter component with monetary formatting.

Changes

Cohort / File(s) Summary
Localization Strings
public/locale/en.json
Added translation keys total_items and total_quantity for displaying delivery order totals.
Delivery Order Totals Feature
src/pages/Facility/services/inventory/externalSupply/deliveryOrder/DeliveryOrderShow.tsx
Implemented calculateDeliveryTotals utility using Decimal arithmetic to aggregate quantities and monetary values from delivery items. Added memoized deliveryTotals computation and renders CardFooter displaying total count, quantity, and value with MonetaryDisplay formatting.
UI Component Exports
src/components/ui/card
Added CardFooter to public exports of Card component module.
🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description is minimal but includes the issue reference (#15499) and a screenshot demonstrating the feature. However, it lacks detail on proposed changes, merge checklist completion, and testing information required by the template. Expand the description to include specific changes made, update the merge checklist to indicate completion status of each item (specs, docs, i18n, QA), and clarify testing coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately describes the main change: displaying delivery totals and count on the delivery order page, which matches the code changes adding totals rendering.
Linked Issues check ✅ Passed The PR successfully implements all requirements from issue #15499: displays item count (total_items), quantity (total_quantity), and monetary value (total_value) in the delivery order view with new UI components and translations.
Out of Scope Changes check ✅ Passed All changes are within scope: translation keys for delivery totals, utility function for calculations, CardFooter component export, and UI integration for displaying totals. No extraneous modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/show-delivery-totals-and-qty

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.

@rithviknishad rithviknishad added P1 breaking issue or vital feature and removed needs testing needs review labels Feb 2, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a footer section to the delivery order details page that displays aggregate statistics for all deliveries in the order, including total item count, total quantity, and total monetary value.

Changes:

  • Implements calculation logic for delivery order totals using Decimal.js for precise arithmetic
  • Adds a new CardFooter component displaying three summary metrics with right-aligned formatting
  • Introduces new i18n keys "total_items" and "total_quantity" for the summary labels

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/pages/Facility/services/inventory/externalSupply/deliveryOrder/DeliveryOrderShow.tsx Adds calculateDeliveryTotals function and displays totals in CardFooter with count, quantity, and value
public/locale/en.json Adds translation keys for "total_items" and "total_quantity"

Comment on lines +254 to +258
if (!supplyDeliveries?.results) {
return { totalCount: 0, totalQuantity: "0", totalValue: "0" };
}
return calculateDeliveryTotals(supplyDeliveries.results, internal);
}, [supplyDeliveries?.results, internal]);
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

The useMemo dependency array includes supplyDeliveries?.results which is an array reference. This will cause recalculation on every query refetch even when the actual delivery data hasn't changed. Consider using a more stable dependency like a serialized version of the results or add the results length as a dependency along with checking if the data has actually changed.

Suggested change
if (!supplyDeliveries?.results) {
return { totalCount: 0, totalQuantity: "0", totalValue: "0" };
}
return calculateDeliveryTotals(supplyDeliveries.results, internal);
}, [supplyDeliveries?.results, internal]);
const results = supplyDeliveries?.results ?? [];
if (!results.length) {
return { totalCount: 0, totalQuantity: "0", totalValue: "0" };
}
return calculateDeliveryTotals(results, internal);
}, [JSON.stringify(supplyDeliveries?.results ?? []), internal]);

Copilot uses AI. Check for mistakes.
let totalValue = new Decimal(0);

for (const delivery of deliveries) {
const qty = new Decimal(delivery.supplied_item_quantity || "0");
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

The fallback to '0' for supplied_item_quantity may mask data integrity issues. Consider whether a null/undefined quantity should be explicitly handled or logged rather than silently treated as zero, as this could hide problems with incomplete delivery records.

Suggested change
const qty = new Decimal(delivery.supplied_item_quantity || "0");
const qtyString = delivery.supplied_item_quantity;
if (qtyString == null) {
// Missing quantity indicates a potentially incomplete delivery record.
// We skip this entry from totals and log for debugging instead of
// silently treating it as zero, which could hide data integrity issues.
// Avoid logging any PHI; inventory identifiers are safe for logs.
// eslint-disable-next-line no-console
console.warn(
"Supply delivery has missing supplied_item_quantity and was excluded from totals.",
);
continue;
}
const qty = new Decimal(qtyString);

Copilot uses AI. Check for mistakes.
@cloudflare-workers-and-pages
Copy link

Deploying care-preview with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2da612a
Status: ✅  Deploy successful!
Preview URL: https://b7ca7227.care-preview-a7w.pages.dev
Branch Preview URL: https://feat-show-delivery-totals-an.care-preview-a7w.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@src/pages/Facility/services/inventory/externalSupply/deliveryOrder/DeliveryOrderShow.tsx`:
- Around line 77-81: The import order is incorrect: the third‑party symbol
Decimal (from "decimal.js") is placed with utils; move the Decimal import into
the third‑party imports block with the other external libraries (so it appears
before internal utils like round, ShortcutBadge, mutate, query) to follow the
3rd‑party → library → CAREUI → UI → components → hooks → utils → relative
ordering; update the import list by cutting the Decimal import and pasting it
into the top third‑party group so only internal utils remain in the utils
section.

Comment on lines +77 to +81
import { round } from "@/Utils/decimal";
import { ShortcutBadge } from "@/Utils/keyboardShortcutComponents";
import mutate from "@/Utils/request/mutate";
import query from "@/Utils/request/query";
import Decimal from "decimal.js";
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Import order: Move Decimal to the 3rd-party imports section.

The Decimal import from decimal.js is a third-party library and should be placed with other 3rd-party imports at the top of the file, not after utility imports. As per coding guidelines, the import order should be: 3rd-party → library → CAREUI → UI → components → hooks → utils → relative.

🔧 Suggested fix

Move line 81 to after the other third-party imports (after line 14):

 import { Trans, useTranslation } from "react-i18next";
 import { toast } from "sonner";
+import Decimal from "decimal.js";
 
 import CareIcon from "@/CAREUI/icons/CareIcon";

And remove it from its current location:

 import { round } from "@/Utils/decimal";
 import { ShortcutBadge } from "@/Utils/keyboardShortcutComponents";
 import mutate from "@/Utils/request/mutate";
 import query from "@/Utils/request/query";
-import Decimal from "decimal.js";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { round } from "@/Utils/decimal";
import { ShortcutBadge } from "@/Utils/keyboardShortcutComponents";
import mutate from "@/Utils/request/mutate";
import query from "@/Utils/request/query";
import Decimal from "decimal.js";
import { round } from "@/Utils/decimal";
import { ShortcutBadge } from "@/Utils/keyboardShortcutComponents";
import mutate from "@/Utils/request/mutate";
import query from "@/Utils/request/query";
🤖 Prompt for AI Agents
In
`@src/pages/Facility/services/inventory/externalSupply/deliveryOrder/DeliveryOrderShow.tsx`
around lines 77 - 81, The import order is incorrect: the third‑party symbol
Decimal (from "decimal.js") is placed with utils; move the Decimal import into
the third‑party imports block with the other external libraries (so it appears
before internal utils like round, ShortcutBadge, mutate, query) to follow the
3rd‑party → library → CAREUI → UI → components → hooks → utils → relative
ordering; update the import list by cutting the Decimal import and pasting it
into the top third‑party group so only internal utils remain in the utils
section.

@github-actions
Copy link

github-actions bot commented Feb 2, 2026

🎭 Playwright Test Results

Status: ❌ Failed
Test Shards: 3

Metric Count
Total Tests 171
✅ Passed 144
❌ Failed 27
⏭️ Skipped 0

📊 Detailed results are available in the playwright-final-report artifact.

Run: #5563

totalQuantity = totalQuantity.plus(qty);

const priceComponents: MonetaryComponent[] = internal
? delivery.supplied_inventory_item?.product?.charge_item_definition
Copy link
Contributor

Choose a reason for hiding this comment

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

Also need to account for category level monetary components.

Copy link
Member Author

@rithviknishad rithviknishad Feb 2, 2026

Choose a reason for hiding this comment

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

ideally when category is auto selected from batch, it should also apply tax. fixing that should automatically solve this. will handle separatley

@bodhish
Copy link
Member

bodhish commented Feb 3, 2026

This won't work, the calculation for total is incorrect

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

Labels

needs review needs testing P1 breaking issue or vital feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

show delivery order totals (item count and amount) in delivery order page

5 participants