Skip to content

Compute average revenue per eligible day and add stock-adjustment history#15

Open
IanTheMitten wants to merge 1 commit into
mainfrom
codex/refactor-revenue-table-for-product-average-calculation
Open

Compute average revenue per eligible day and add stock-adjustment history#15
IanTheMitten wants to merge 1 commit into
mainfrom
codex/refactor-revenue-table-for-product-average-calculation

Conversation

@IanTheMitten

Copy link
Copy Markdown
Owner

Motivation

  • Provide an availability-aware ranking of products by computing average revenue per eligible day (exclude weekends and no-transaction days and days where a product was fully out of stock).
  • Reconstruct per-product day-level stock using sales + adjustment events so eligibility reflects historical inventory, not just current snapshot.

Description

  • Refactored RevenueByProductTable to compute productAvgRevenuePerDay = productRevenueOnSampledDays / eligibleDaysForThatProduct, where sampled days are weekday transaction days only and results are sorted by average revenue per eligible day, showing top 10 by default with a Show all / Show top 10 toggle in the header.
  • Reconstructed stock timelines from both sales (negative deltas derived from full transaction history) and explicit stock adjustments (positive/negative deltas), and implemented computeEligibleDaysForProduct to count eligible days excluding days with zero stock for the full day.
  • Added persistent stock_adjustments IndexedDB store and API surface: bumped DB version to 3, added getAllStockAdjustments in localDb and productsAPI.getStockAdjustments, loaded adjustments on startup into app state, and persisted adjustment records when calling productsAPI.adjustStock.
  • Wired BudgetPage -> RevenueByProductTable to pass both filtered transactions (for sampled revenue) and full transaction history + stockHistory (for reconstructing stock) while preserving existing currency and table styling conventions.

Testing

  • Built the app with npm run build and the production build completed successfully.
  • No unit tests were added; the change was validated by a successful production build.

Codex Task

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant