feat(finance): manual income tracking included in revenue - #53
Merged
Conversation
|
🔥 Firebase Hosting preview: https://open-ten99--pr-53-e52c29ui.web.app |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds manual income tracking to the Transactions page and rolls it into revenue/income KPIs.
Part 1 — Service layer
createManualIncome(input)inweb/src/services/firestore.ts— writes atransactionsdoc withprovider:'manual',type:'income',isManual:true, positiveamount,date,description,category(defaults toManual Income),ownerId(current uid),createdAt/updatedAt. Mirrors the existingcreateManualExpenseconventions (addDoc + Timestamp). TheTransactionmodel has no client field, so source belongs indescription(no model redesign).subscribeTransactions(callback)— onSnapshot listener over the user'stransactions, mirroringsubscribeReceipts.useTransactions()hook inweb/src/hooks/useFirestore.ts, mirroringuseReceipts/useConnectedAccounts.Part 2 — Transactions page UI
web/src/components/finance/AddIncomeModal.tsx, mirroringNewInvoiceModalstyling tokens and validation conventions. Fields: amount (required, > 0), date (required, defaults to today), description/source (required), category (optional, defaults toManual Income).createManualIncomeand refetches the list using the existing pagination refetch pattern.TransactionRowalready renders a "Manual" source badge forprovider==='manual'and styles positive amounts (income) green with a+prefix.Part 3 — Revenue/Dashboard inclusion + double-count rule
calculateRevenue(items, range, transactions = [])inweb/src/lib/finance.tsnow adds the sum of manual income transactions (provider==='manual' && type==='income') whosedateis in range. Signature is backward compatible (optionaltransactionsdefaulting to[]).matchedWorkItemIdare EXCLUDED, since those are tied to an already-counted invoice.FinanceOverview.tsxnow passesuseTransactions()data intocalculateRevenue(current and previous period).Dashboard.tsx"revenue this month" adds in-range manual income with the same exclusion rule (kept the existing inline invoice predicate untouched to avoid changing invoice behavior).Constraints respected
No changes to Plaid/Stripe sync, invoice/work-order predicates, routing (no new route — lives on the Transactions page), or unrelated finance logic. Existing styling tokens, TS conventions, and immutable patterns followed. No new dependencies.
Test plan
cd web && npx tsc -b— exit 0.npx vitest run— 75/75 pass (full suite).finance.test.tsextended withcalculateRevenuecases:matchedWorkItemIdexcluded (double-count guard)main(pre-existing repo errors unchanged; new files lint clean).