diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index bf7da4cfcdd0..39e80022b6a4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -781,6 +781,7 @@ type TransactionDetails = { attendees: Attendee[] | string; taxAmount?: number; taxCode?: string; + taxValue?: string; currency: string; merchant: string; waypoints?: WaypointCollection | string; @@ -4679,6 +4680,7 @@ function getTransactionDetails( attendees: getAttendees(transaction, currentUserDetails), taxAmount: getTaxAmount(transaction, isFromExpenseReport), taxCode: getTaxCode(transaction), + taxValue: transaction.taxValue, currency: getCurrency(transaction), comment: getDescription(transaction), merchant: getMerchant(transaction), diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index 3bd854c5d468..62fd158d0df6 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -101,6 +101,7 @@ type TransactionParams = { tag?: string; taxCode?: string; taxAmount?: number; + taxValue?: string; billable?: boolean; pendingFields?: Partial>>; reimbursable?: boolean; @@ -437,6 +438,7 @@ function buildOptimisticTransaction(params: BuildOptimisticTransactionParams): T tag = '', taxCode = '', taxAmount = 0, + taxValue, billable = false, pendingFields, reimbursable = true, @@ -550,6 +552,7 @@ function buildOptimisticTransaction(params: BuildOptimisticTransactionParams): T tag, taxCode, taxAmount, + taxValue, modifiedAmount, billable, reimbursable, diff --git a/src/libs/actions/IOU/MoneyRequest.ts b/src/libs/actions/IOU/MoneyRequest.ts index 3ee72fe80b56..a4c1a05f42f6 100644 --- a/src/libs/actions/IOU/MoneyRequest.ts +++ b/src/libs/actions/IOU/MoneyRequest.ts @@ -86,6 +86,7 @@ type InitialTransactionParams = { reportID?: string; taxCode: string; taxAmount: number; + taxValue?: string; isFromGlobalCreate?: boolean; currency?: string; participants?: Participant[]; @@ -390,6 +391,7 @@ function handleMoneyRequestStepScanParticipants({ currency: initialTransaction?.currency ?? 'USD', taxCode: initialTransaction.taxCode, taxAmount: initialTransaction.taxAmount, + taxValue: initialTransaction.taxValue, quickAction, policyRecentlyUsedCurrencies: policyRecentlyUsedCurrencies ?? [], // No need to update recently used tags because no tags are used when the confirmation step is skipped diff --git a/src/libs/actions/IOU/SendInvoice.ts b/src/libs/actions/IOU/SendInvoice.ts index 29a2c298297c..19ce3984f710 100644 --- a/src/libs/actions/IOU/SendInvoice.ts +++ b/src/libs/actions/IOU/SendInvoice.ts @@ -597,7 +597,7 @@ function getSendInvoiceInformation({ policyRecentlyUsedCategories, policyRecentlyUsedTags, }: SendInvoiceOptions): SendInvoiceInformation { - const {amount = 0, currency = '', created = '', merchant = '', category = '', tag = '', taxCode = '', taxAmount = 0, billable, comment, participants} = transaction ?? {}; + const {amount = 0, currency = '', created = '', merchant = '', category = '', tag = '', taxCode = '', taxAmount = 0, taxValue, billable, comment, participants} = transaction ?? {}; const trimmedComment = (comment?.comment ?? '').trim(); const senderWorkspaceID = participants?.find((participant) => participant?.isSender)?.policyID; const receiverParticipant: Participant | InvoiceReceiver | undefined = @@ -644,6 +644,7 @@ function getSendInvoiceInformation({ tag, taxCode, taxAmount, + taxValue, billable, reimbursable: true, }, diff --git a/src/libs/actions/IOU/Split.ts b/src/libs/actions/IOU/Split.ts index 66837b0381c9..81bc3e5bcdcb 100644 --- a/src/libs/actions/IOU/Split.ts +++ b/src/libs/actions/IOU/Split.ts @@ -143,6 +143,7 @@ type SplitBillActionsParams = { splitShares?: SplitShares; taxCode?: string; taxAmount?: number; + taxValue?: string; isRetry?: boolean; policyRecentlyUsedCategories?: OnyxEntry; policyRecentlyUsedTags: OnyxEntry; @@ -176,6 +177,7 @@ function splitBill({ splitShares = {}, taxCode = '', taxAmount = 0, + taxValue, policyRecentlyUsedCategories, isASAPSubmitBetaEnabled, transactionViolations, @@ -205,6 +207,7 @@ function splitBill({ iouRequestType, taxCode, taxAmount, + taxValue, }, policyRecentlyUsedCategories, policyRecentlyUsedTags, @@ -268,6 +271,7 @@ function splitBillAndOpenReport({ splitShares = {}, taxCode = '', taxAmount = 0, + taxValue, existingSplitChatReportID, policyRecentlyUsedCategories, policyRecentlyUsedTags, @@ -299,6 +303,7 @@ function splitBillAndOpenReport({ iouRequestType, taxCode, taxAmount, + taxValue, }, policyRecentlyUsedCategories, policyRecentlyUsedTags, @@ -359,6 +364,7 @@ function startSplitBill({ currency, taxCode = '', taxAmount = 0, + taxValue, shouldPlaySound = true, policyRecentlyUsedCategories, policyRecentlyUsedTags, @@ -385,6 +391,7 @@ function startSplitBill({ tag, taxCode, taxAmount, + taxValue, billable, reimbursable, }, @@ -545,6 +552,7 @@ function startSplitBill({ currency, taxCode, taxAmount, + taxValue, quickAction, policyRecentlyUsedCurrencies, policyRecentlyUsedTags, @@ -907,6 +915,7 @@ function completeSplitBill( tag: updatedTransaction?.tag, taxCode: updatedTransaction?.taxCode, taxAmount: isPolicyExpenseChat ? -splitTaxAmount : splitAmount, + taxValue: updatedTransaction?.taxValue, billable: updatedTransaction?.billable, reimbursable: updatedTransaction?.reimbursable, source: CONST.IOU.TYPE.SPLIT, @@ -1183,6 +1192,7 @@ function updateSplitTransactions({ reimbursable: originalTransactionDetails?.reimbursable, taxCode: originalTransactionDetails?.taxCode, taxAmount: calculateIOUAmount(splitExpenses.length - 1, originalTransactionDetails?.taxAmount ?? 0, originalTransactionDetails?.currency ?? CONST.CURRENCY.USD, false), + taxValue: originalTransactionDetails?.taxValue, billable: originalTransactionDetails?.billable, waypoints: splitExpense.waypoints, customUnit: splitExpense.customUnit, @@ -1216,6 +1226,7 @@ function updateSplitTransactions({ linkedTrackedExpenseReportAction: currentReportAction, taxCode: originalTransactionDetails?.taxCode, taxAmount: calculateIOUAmount(splitExpenses.length - 1, originalTransactionDetails?.taxAmount ?? 0, originalTransactionDetails?.currency ?? CONST.CURRENCY.USD, false), + taxValue: originalTransactionDetails?.taxValue, billable: originalTransactionDetails?.billable, waypoints: splitExpense.waypoints, customUnit: splitExpense.customUnit, diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index 3841fd6e1bca..9c970205200f 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -277,6 +277,7 @@ type BaseTransactionParams = { tag?: string; taxCode?: string; taxAmount?: number; + taxValue?: string; billable?: boolean; reimbursable?: boolean; customUnitRateID?: string; @@ -379,13 +380,14 @@ type TrackExpenseInformation = { onyxData: OnyxData; }; -type TrackedExpenseTransactionParams = Omit & { +type TrackedExpenseTransactionParams = Omit & { waypoints?: string; distance?: number; transactionID: string | undefined; receipt?: Receipt; taxCode: string; taxAmount: number; + taxValue?: string; attendees?: Attendee[]; }; @@ -680,6 +682,7 @@ type TrackExpenseTransactionParams = { tag?: string; taxCode?: string; taxAmount?: number; + taxValue?: string; billable?: boolean; reimbursable?: boolean; validWaypoints?: WaypointCollection; @@ -735,6 +738,7 @@ type GetTrackExpenseInformationTransactionParams = { tag?: string; taxCode?: string; taxAmount?: number; + taxValue?: string; billable?: boolean; reimbursable?: boolean; linkedTrackedExpenseReportAction?: OnyxTypes.ReportAction; @@ -792,6 +796,7 @@ type StartSplitBilActionParams = { currency: string; taxCode: string; taxAmount: number; + taxValue?: string; shouldPlaySound?: boolean; policyRecentlyUsedCategories?: OnyxEntry; policyRecentlyUsedTags: OnyxEntry; @@ -3305,6 +3310,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma tag, taxCode, taxAmount, + taxValue, billable, reimbursable = true, linkedTrackedExpenseReportAction, @@ -3468,6 +3474,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma taxCode, source, taxAmount: isExpenseReport(iouReport) ? -(taxAmount ?? 0) : taxAmount, + taxValue, billable, pendingAction, pendingFields: isDistanceRequest && !isManualDistanceRequest ? {waypoints: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, ...pendingFields} : pendingFields, @@ -3735,6 +3742,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T tag, taxCode, taxAmount, + taxValue, billable, reimbursable, linkedTrackedExpenseReportAction, @@ -3946,6 +3954,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T tag, taxCode, taxAmount: taxAmount ? -taxAmount : undefined, + taxValue, billable, pendingFields: isDistanceRequest && !isManualDistanceRequest ? {waypoints: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD} : undefined, reimbursable, @@ -6660,6 +6669,7 @@ function trackExpense(params: CreateTrackExpenseParams) { tag, taxCode = '', taxAmount = 0, + taxValue, billable, reimbursable, gpsPoint, @@ -6705,6 +6715,7 @@ function trackExpense(params: CreateTrackExpenseParams) { tag, taxCode, taxAmount, + taxValue, billable, reimbursable, validWaypoints, @@ -6758,6 +6769,7 @@ function trackExpense(params: CreateTrackExpenseParams) { tag, taxCode, taxAmount, + taxValue, billable, reimbursable, linkedTrackedExpenseReportAction, @@ -7062,6 +7074,7 @@ function createSplitsAndOnyxData({ iouRequestType = CONST.IOU.REQUEST_TYPE.MANUAL, taxCode = '', taxAmount = 0, + taxValue, attendees, }, policyRecentlyUsedCategories, @@ -7099,6 +7112,7 @@ function createSplitsAndOnyxData({ tag, taxCode, taxAmount, + taxValue, billable, reimbursable, pendingFields: isDistanceRequest ? {waypoints: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD} : undefined, @@ -7403,6 +7417,7 @@ function createSplitsAndOnyxData({ tag, taxCode, taxAmount: isExpenseReport(oneOnOneIOUReport) ? -splitTaxAmount : splitTaxAmount, + taxValue, billable, source: CONST.IOU.TYPE.SPLIT, }, @@ -7599,6 +7614,7 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest tag, taxAmount, taxCode, + taxValue, merchant, modifiedAmount, billable, @@ -7653,6 +7669,7 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest iouRequestType: CONST.IOU.REQUEST_TYPE.DISTANCE, taxCode, taxAmount, + taxValue, attendees, }, policyRecentlyUsedCategories, @@ -7734,6 +7751,7 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest tag, taxCode, taxAmount, + taxValue, billable, reimbursable, attendees, diff --git a/src/pages/Share/SubmitDetailsPage.tsx b/src/pages/Share/SubmitDetailsPage.tsx index c19904f6894e..8f5c405fec16 100644 --- a/src/pages/Share/SubmitDetailsPage.tsx +++ b/src/pages/Share/SubmitDetailsPage.tsx @@ -32,7 +32,7 @@ import {getParticipantsOption, getReportOption} from '@libs/OptionsListUtils'; import {hasOnlyPersonalPolicies as hasOnlyPersonalPoliciesUtil} from '@libs/PolicyUtils'; import {shouldValidateFile} from '@libs/ReceiptUtils'; import {getReportOrDraftReport, isSelfDM} from '@libs/ReportUtils'; -import {getDefaultTaxCode} from '@libs/TransactionUtils'; +import {getDefaultTaxCode, getTaxValue} from '@libs/TransactionUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; @@ -129,6 +129,7 @@ function SubmitDetailsPage({ const transactionTaxAmount = transaction?.taxAmount ?? 0; const defaultTaxCode = getDefaultTaxCode(policy, transaction); const transactionTaxCode = (transaction?.taxCode ? transaction?.taxCode : defaultTaxCode) ?? ''; + const transactionTaxValue = transaction?.taxValue ?? getTaxValue(policy, transaction, transactionTaxCode) ?? ''; const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); const [recentWaypoints] = useOnyx(ONYXKEYS.NVP_RECENT_WAYPOINTS); @@ -153,6 +154,7 @@ function SubmitDetailsPage({ tag: transaction.tag, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, billable: transaction.billable, reimbursable: transaction.reimbursable, merchant: transaction.merchant ?? '', @@ -193,6 +195,7 @@ function SubmitDetailsPage({ tag: transaction.tag, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, billable: transaction.billable, reimbursable: transaction.reimbursable, merchant: transaction.merchant ?? '', diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 47df1a1f22f7..3abd7f1133ec 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -74,6 +74,7 @@ import { getDefaultTaxCode, getRateID, getRequestType, + getTaxValue, getValidWaypoints, hasReceipt, isDistanceRequest as isDistanceRequestTransactionUtils, @@ -303,6 +304,7 @@ function IOURequestStepConfirmation({ const defaultTaxCode = getDefaultTaxCode(policy, transaction); const transactionTaxCode = (transaction?.taxCode ? transaction?.taxCode : defaultTaxCode) ?? ''; const transactionTaxAmount = transaction?.taxAmount ?? 0; + const transactionTaxValue = transaction?.taxValue ?? getTaxValue(policy, transaction, transactionTaxCode) ?? ''; const isSharingTrackExpense = action === CONST.IOU.ACTION.SHARE; const isCategorizingTrackExpense = action === CONST.IOU.ACTION.CATEGORIZE; const isMovingTransactionFromTrackExpense = isMovingTransactionFromTrackExpenseIOUUtils(action); @@ -692,6 +694,7 @@ function IOURequestStepConfirmation({ tag: item.tag, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, billable: item.billable, reimbursable: item.reimbursable, actionableWhisperReportActionID: item.actionableWhisperReportActionID, @@ -744,6 +747,7 @@ function IOURequestStepConfirmation({ isManualDistanceRequest, transactionTaxCode, transactionTaxAmount, + transactionTaxValue, customUnitRateID, isTimeRequest, shouldGenerateTransactionThreadReport, @@ -901,6 +905,7 @@ function IOURequestStepConfirmation({ tag: item.tag, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, billable: item.billable, reimbursable: item.reimbursable, gpsPoint, @@ -950,6 +955,7 @@ function IOURequestStepConfirmation({ receiptFiles, transactionTaxCode, transactionTaxAmount, + transactionTaxValue, customUnitRateID, gpsDraftDetails, isASAPSubmitBetaEnabled, @@ -994,6 +1000,7 @@ function IOURequestStepConfirmation({ tag: transaction.tag, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, customUnitRateID, splitShares: transaction.splitShares, validWaypoints: getValidWaypoints(transaction.comment?.waypoints, true, isGPSDistanceRequest), @@ -1030,6 +1037,7 @@ function IOURequestStepConfirmation({ transactionDistance, transactionTaxCode, transactionTaxAmount, + transactionTaxValue, customUnitRateID, isManualDistanceRequest, isOdometerDistanceRequest, @@ -1146,6 +1154,7 @@ function IOURequestStepConfirmation({ currency: item.currency, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, shouldPlaySound: index === transactions.length - 1, policyRecentlyUsedCategories, policyRecentlyUsedTags, @@ -1181,6 +1190,7 @@ function IOURequestStepConfirmation({ splitShares: transaction.splitShares, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, policyRecentlyUsedCategories, policyRecentlyUsedTags, isASAPSubmitBetaEnabled, @@ -1215,6 +1225,7 @@ function IOURequestStepConfirmation({ splitShares: transaction.splitShares, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, policyRecentlyUsedCategories, policyRecentlyUsedTags, isASAPSubmitBetaEnabled, @@ -1333,6 +1344,7 @@ function IOURequestStepConfirmation({ report, transactionTaxCode, transactionTaxAmount, + transactionTaxValue, policyRecentlyUsedCategories, policyRecentlyUsedTags, quickAction, diff --git a/src/pages/iou/request/step/IOURequestStepScan/hooks/useReceiptScan.ts b/src/pages/iou/request/step/IOURequestStepScan/hooks/useReceiptScan.ts index 7f374973c900..f5722bc6aa57 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/hooks/useReceiptScan.ts +++ b/src/pages/iou/request/step/IOURequestStepScan/hooks/useReceiptScan.ts @@ -17,7 +17,7 @@ import {getMoneyRequestParticipantOptions, handleMoneyRequestStepScanParticipant import setTestReceipt from '@libs/actions/setTestReceipt'; import {isArchivedReport, isPolicyExpenseChat} from '@libs/ReportUtils'; import {getSpan, startSpan} from '@libs/telemetry/activeSpans'; -import {getDefaultTaxCode, hasReceipt, shouldReuseInitialTransaction} from '@libs/TransactionUtils'; +import {getDefaultTaxCode, getTaxValue, hasReceipt, shouldReuseInitialTransaction} from '@libs/TransactionUtils'; import type {ReceiptFile, UseReceiptScanParams} from '@pages/iou/request/step/IOURequestStepScan/types'; import {setMoneyRequestReceipt} from '@userActions/IOU'; import {buildOptimisticTransactionAndCreateDraft, removeDraftTransactions} from '@userActions/TransactionEdit'; @@ -77,6 +77,7 @@ function useReceiptScan({ const defaultTaxCode = getDefaultTaxCode(policy, initialTransaction); const transactionTaxCode = (initialTransaction?.taxCode ? initialTransaction?.taxCode : defaultTaxCode) ?? ''; const transactionTaxAmount = initialTransaction?.taxAmount ?? 0; + const transactionTaxValue = initialTransaction?.taxValue ?? getTaxValue(policy, initialTransaction, transactionTaxCode) ?? ''; // For quick button actions, we'll skip the confirmation page unless the report is archived or this is a workspace // request and the workspace requires a category or a tag @@ -122,6 +123,7 @@ function useReceiptScan({ reportID: initialTransaction?.reportID, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, currency: initialTransaction?.currency, isFromGlobalCreate: initialTransaction?.isFromGlobalCreate, participants: initialTransaction?.participants, diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 18600814b0da..24854836cb8f 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -96,6 +96,7 @@ import { getReportPreviewMessage, getReportStatusTranslation, getReportSubtitlePrefix, + getTransactionDetails, getViolatingReportIDForRBRInLHN, getWorkspaceIcon, getWorkspaceNameUpdatedMessage, @@ -14575,4 +14576,62 @@ describe('ReportUtils', () => { }); }); }); + + describe('getTransactionDetails', () => { + it('should return taxValue from the transaction', () => { + const transaction = buildOptimisticTransaction({ + transactionParams: { + amount: 1000, + currency: 'USD', + reportID: '1', + comment: '', + created: '2024-01-01', + taxCode: 'id_TAX_RATE_1', + taxAmount: 0, + taxValue: '0%', + }, + }); + + const details = getTransactionDetails(transaction); + + expect(details?.taxValue).toBe('0%'); + expect(details?.taxCode).toBe('id_TAX_RATE_1'); + expect(details?.taxAmount).toBe(0); + }); + + it('should return undefined taxValue when not set on the transaction', () => { + const transaction = buildOptimisticTransaction({ + transactionParams: { + amount: 500, + currency: 'USD', + reportID: '1', + comment: '', + created: '2024-01-01', + }, + }); + + const details = getTransactionDetails(transaction); + + expect(details?.taxValue).toBeUndefined(); + }); + + it('should return non-zero taxValue from the transaction', () => { + const transaction = buildOptimisticTransaction({ + transactionParams: { + amount: 1000, + currency: 'USD', + reportID: '1', + comment: '', + created: '2024-01-01', + taxCode: 'id_TAX_RATE_1', + taxAmount: 100, + taxValue: '10%', + }, + }); + + const details = getTransactionDetails(transaction); + + expect(details?.taxValue).toBe('10%'); + }); + }); }); diff --git a/tests/unit/TransactionUtilsTest.ts b/tests/unit/TransactionUtilsTest.ts index c1d15d598490..3c21b6e2d7fb 100644 --- a/tests/unit/TransactionUtilsTest.ts +++ b/tests/unit/TransactionUtilsTest.ts @@ -450,6 +450,32 @@ describe('TransactionUtils', () => { expect(updatedTransaction.modifiedAmount).toBe(newAmount); }); + + it('should update taxValue when taxValue and taxCode are both in transactionChanges', () => { + const transaction = generateTransaction(); + + const updatedTransaction = TransactionUtils.getUpdatedTransaction({ + transaction, + isFromExpenseReport: true, + transactionChanges: {taxCode: 'id_TAX_RATE_1', taxAmount: 50, taxValue: '5%'}, + }); + + expect(updatedTransaction.taxValue).toBe('5%'); + expect(updatedTransaction.taxCode).toBe('id_TAX_RATE_1'); + expect(updatedTransaction.taxAmount).toBe(-50); + }); + + it('should not update taxValue when taxCode is not in transactionChanges', () => { + const transaction = generateTransaction({taxValue: '10%'}); + + const updatedTransaction = TransactionUtils.getUpdatedTransaction({ + transaction, + isFromExpenseReport: false, + transactionChanges: {taxValue: '5%'}, + }); + + expect(updatedTransaction.taxValue).toBe('10%'); + }); }); describe('isScanning', () => {