From 2f4d561ffbedd7ed4273baa30c109814f99fcf99 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Sun, 5 May 2024 04:32:26 +0530 Subject: [PATCH 01/29] fix: [Violations] Distance - Incorrect error message when distance amount is changed to smaller amount. Signed-off-by: Krishna Gupta --- src/CONST.ts | 4 ++-- src/components/ReceiptAudit.tsx | 13 ++++++++++--- .../ReportActionItem/MoneyRequestView.tsx | 11 ++++++----- src/hooks/useViolations.ts | 16 +++++++++++----- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 566d5179f86a..e0dd65fb2ef1 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3619,9 +3619,9 @@ const CONST = { SMARTSCAN_FAILED: 'smartscanFailed', SOME_TAG_LEVELS_REQUIRED: 'someTagLevelsRequired', TAG_OUT_OF_POLICY: 'tagOutOfPolicy', - TAX_AMOUNT_CHANGED: 'taxAmountChanged', + // TAX_AMOUNT_CHANGED: 'taxAmountChanged', + // TAX_RATE_CHANGED: 'taxRateChanged', TAX_OUT_OF_POLICY: 'taxOutOfPolicy', - TAX_RATE_CHANGED: 'taxRateChanged', TAX_REQUIRED: 'taxRequired', }, diff --git a/src/components/ReceiptAudit.tsx b/src/components/ReceiptAudit.tsx index ac1b36c6bf32..2adf3c2601d5 100644 --- a/src/components/ReceiptAudit.tsx +++ b/src/components/ReceiptAudit.tsx @@ -7,17 +7,24 @@ import Icon from './Icon'; import * as Expensicons from './Icon/Expensicons'; import Text from './Text'; -function ReceiptAuditHeader({notes, shouldShowAuditMessage}: {notes: string[]; shouldShowAuditMessage: boolean}) { +function ReceiptAuditHeader({notes, shouldShowAuditSuccess, shouldShowAuditFailure}: {notes: string[]; shouldShowAuditSuccess?: boolean; shouldShowAuditFailure?: boolean}) { const styles = useThemeStyles(); const theme = useTheme(); const {translate} = useLocalize(); - const auditText = notes.length > 0 ? translate('iou.receiptIssuesFound', notes.length) : translate('common.verified'); + let auditText = ''; + + if (notes.length > 0 && shouldShowAuditFailure) { + auditText = translate('iou.receiptIssuesFound', notes.length); + } else if (!notes.length && shouldShowAuditSuccess) { + auditText = translate('common.verified'); + } + return ( {translate('common.receipt')} - {shouldShowAuditMessage && ( + {auditText && ( <> {` • ${auditText}`} !!canUseViolations && getViolationsForField(field, data).length > 0, [canUseViolations, getViolationsForField], @@ -330,7 +330,7 @@ function MoneyRequestView({ const shouldShowMapOrReceipt = showMapAsImage || hasReceipt; const shouldShowReceiptEmptyState = !hasReceipt && !isInvoice && (canEditReceipt || isAdmin || isApprover); const noticeTypeViolations = transactionViolations?.filter((violation) => violation.type === 'notice').map((v) => ViolationsUtils.getViolationTranslation(v, translate)) ?? []; - const shouldShowNotesViolations = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report); + const shouldShowAuditMessage = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report); return ( @@ -339,7 +339,8 @@ function MoneyRequestView({ {!isInvoice && ( )} {shouldShowMapOrReceipt && ( @@ -393,7 +394,7 @@ function MoneyRequestView({ /> )} {!shouldShowReceiptEmptyState && !shouldShowMapOrReceipt && } - {shouldShowNotesViolations && } + {/* {shouldShowNotesViolations && } */} {canUseViolations && } = { smartscanFailed: 'receipt', someTagLevelsRequired: 'tag', tagOutOfPolicy: 'tag', - taxAmountChanged: 'tax', + // taxAmountChanged: 'tax', + // taxRateChanged: 'tax', taxOutOfPolicy: 'tax', - taxRateChanged: 'tax', taxRequired: 'tax', }; type ViolationsMap = Map; -function useViolations(violations: TransactionViolation[]) { +function useViolations(violations: TransactionViolation[], shouldIncludeNoticeViolations?: boolean) { const violationsByField = useMemo((): ViolationsMap => { - const filteredViolations = violations.filter((violation) => violation.type === CONST.VIOLATION_TYPES.VIOLATION); + const filteredViolations = violations.filter((violation) => { + if (!shouldIncludeNoticeViolations) { + return violation.type === CONST.VIOLATION_TYPES.VIOLATION; + } + return violation.type === CONST.VIOLATION_TYPES.VIOLATION || violation.type === CONST.VIOLATION_TYPES.NOTICE; + }); + const violationGroups = new Map(); for (const violation of filteredViolations) { const field = violationFields[violation.name]; @@ -58,7 +64,7 @@ function useViolations(violations: TransactionViolation[]) { violationGroups.set(field, [...existingViolations, violation]); } return violationGroups ?? new Map(); - }, [violations]); + }, [violations, shouldIncludeNoticeViolations]); const getViolationsForField = useCallback( (field: ViolationField, data?: TransactionViolation['data']) => { From bac54f14cff9ca95447ea7c4ac5aa17b5925721a Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Sun, 5 May 2024 04:41:51 +0530 Subject: [PATCH 02/29] remove tax rate changed violation. Signed-off-by: Krishna Gupta --- src/CONST.ts | 3 +-- src/hooks/useViolations.ts | 3 +-- src/libs/Violations/ViolationsUtils.ts | 2 -- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index e0dd65fb2ef1..97a7c551da5a 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3619,8 +3619,7 @@ const CONST = { SMARTSCAN_FAILED: 'smartscanFailed', SOME_TAG_LEVELS_REQUIRED: 'someTagLevelsRequired', TAG_OUT_OF_POLICY: 'tagOutOfPolicy', - // TAX_AMOUNT_CHANGED: 'taxAmountChanged', - // TAX_RATE_CHANGED: 'taxRateChanged', + TAX_AMOUNT_CHANGED: 'taxAmountChanged', TAX_OUT_OF_POLICY: 'taxOutOfPolicy', TAX_REQUIRED: 'taxRequired', }, diff --git a/src/hooks/useViolations.ts b/src/hooks/useViolations.ts index bf2e8315194a..125a38e48220 100644 --- a/src/hooks/useViolations.ts +++ b/src/hooks/useViolations.ts @@ -40,8 +40,7 @@ const violationFields: Record = { smartscanFailed: 'receipt', someTagLevelsRequired: 'tag', tagOutOfPolicy: 'tag', - // taxAmountChanged: 'tax', - // taxRateChanged: 'tax', + taxAmountChanged: 'tax', taxOutOfPolicy: 'tax', taxRequired: 'tax', }; diff --git a/src/libs/Violations/ViolationsUtils.ts b/src/libs/Violations/ViolationsUtils.ts index 42f58be1d699..5e38d213edaa 100644 --- a/src/libs/Violations/ViolationsUtils.ts +++ b/src/libs/Violations/ViolationsUtils.ts @@ -276,8 +276,6 @@ const ViolationsUtils = { return translate('violations.taxAmountChanged'); case 'taxOutOfPolicy': return translate('violations.taxOutOfPolicy', {taxName}); - case 'taxRateChanged': - return translate('violations.taxRateChanged'); case 'taxRequired': return translate('violations.taxRequired'); default: From d3994531be44330e015fd1d43c628b8f0ba0643f Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Sun, 5 May 2024 04:43:44 +0530 Subject: [PATCH 03/29] remove ReceiptAuditHeader. Signed-off-by: Krishna Gupta --- src/components/ReceiptAudit.tsx | 9 ++------- src/components/ReportActionItem/MoneyRequestView.tsx | 5 ++--- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/components/ReceiptAudit.tsx b/src/components/ReceiptAudit.tsx index 2adf3c2601d5..a5ccf543e0b7 100644 --- a/src/components/ReceiptAudit.tsx +++ b/src/components/ReceiptAudit.tsx @@ -7,7 +7,7 @@ import Icon from './Icon'; import * as Expensicons from './Icon/Expensicons'; import Text from './Text'; -function ReceiptAuditHeader({notes, shouldShowAuditSuccess, shouldShowAuditFailure}: {notes: string[]; shouldShowAuditSuccess?: boolean; shouldShowAuditFailure?: boolean}) { +function ReceiptAudit({notes, shouldShowAuditSuccess, shouldShowAuditFailure}: {notes: string[]; shouldShowAuditSuccess?: boolean; shouldShowAuditFailure?: boolean}) { const styles = useThemeStyles(); const theme = useTheme(); const {translate} = useLocalize(); @@ -41,9 +41,4 @@ function ReceiptAuditHeader({notes, shouldShowAuditSuccess, shouldShowAuditFailu ); } -function ReceiptAuditMessages({notes = []}: {notes?: string[]}) { - const styles = useThemeStyles(); - return {notes.length > 0 && notes.map((message) => {message})}; -} - -export {ReceiptAuditHeader, ReceiptAuditMessages}; +export default ReceiptAudit; diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 0f9ffc2d2485..2b91b41e8cdc 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -7,7 +7,7 @@ import * as Expensicons from '@components/Icon/Expensicons'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; import {useSession} from '@components/OnyxProvider'; -import {ReceiptAuditHeader} from '@components/ReceiptAudit'; +import ReceiptAudit from '@components/ReceiptAudit'; import ReceiptEmptyState from '@components/ReceiptEmptyState'; import Switch from '@components/Switch'; import Text from '@components/Text'; @@ -337,7 +337,7 @@ function MoneyRequestView({ {shouldShowAnimatedBackground && } {!isInvoice && ( - )} {!shouldShowReceiptEmptyState && !shouldShowMapOrReceipt && } - {/* {shouldShowNotesViolations && } */} {canUseViolations && } Date: Fri, 10 May 2024 15:28:23 +0530 Subject: [PATCH 04/29] updated amountModified translation. Signed-off-by: Krishna Gupta --- src/CONST.ts | 1 + src/hooks/useViolations.ts | 4 ++++ src/languages/en.ts | 15 ++++++++++++++- src/languages/es.ts | 15 ++++++++++++++- src/languages/types.ts | 3 +++ src/libs/Violations/ViolationsUtils.ts | 2 +- 6 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index ce8e0dc8aeca..efb0463457b1 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3651,6 +3651,7 @@ const CONST = { TAG_OUT_OF_POLICY: 'tagOutOfPolicy', TAX_AMOUNT_CHANGED: 'taxAmountChanged', TAX_OUT_OF_POLICY: 'taxOutOfPolicy', + TAX_RATE_CHANGED: 'taxRateChanged', TAX_REQUIRED: 'taxRequired', }, diff --git a/src/hooks/useViolations.ts b/src/hooks/useViolations.ts index 125a38e48220..4f35c6d27a73 100644 --- a/src/hooks/useViolations.ts +++ b/src/hooks/useViolations.ts @@ -40,6 +40,7 @@ const violationFields: Record = { smartscanFailed: 'receipt', someTagLevelsRequired: 'tag', tagOutOfPolicy: 'tag', + taxRateChanged: 'tax', taxAmountChanged: 'tax', taxOutOfPolicy: 'tax', taxRequired: 'tax', @@ -50,6 +51,9 @@ type ViolationsMap = Map; function useViolations(violations: TransactionViolation[], shouldIncludeNoticeViolations?: boolean) { const violationsByField = useMemo((): ViolationsMap => { const filteredViolations = violations.filter((violation) => { + if (violation.name === 'taxRateChanged' || violation.name === 'taxAmountChanged') { + return false; + } if (!shouldIncludeNoticeViolations) { return violation.type === CONST.VIOLATION_TYPES.VIOLATION; } diff --git a/src/languages/en.ts b/src/languages/en.ts index 75ef134a6175..7faa4ed1804c 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -88,6 +88,7 @@ import type { ViolationsInvoiceMarkupParams, ViolationsMaxAgeParams, ViolationsMissingTagParams, + ViolationsModifiedAmountParams, ViolationsOverCategoryLimitParams, ViolationsOverLimitParams, ViolationsPerDayLimitParams, @@ -2959,7 +2960,19 @@ export default { missingCategory: 'Missing category', missingComment: 'Description required for selected category', missingTag: ({tagName}: ViolationsMissingTagParams) => `Missing ${tagName ?? 'tag'}`, - modifiedAmount: 'Amount greater than scanned receipt', + modifiedAmount: ({type, displayPercentVariance}: ViolationsModifiedAmountParams): string => { + if (type === 'card' && displayPercentVariance) { + return `Amount ${displayPercentVariance}% greater than scanned receipt`; + } + switch (type) { + case 'distance': + return 'Amount differs from calculated distance'; + case 'card': + return 'Amount greater than card transaction'; + default: + return 'Amount greater than scanned receipt'; + } + }, modifiedDate: 'Date differs from scanned receipt', nonExpensiworksExpense: 'Non-Expensiworks expense', overAutoApprovalLimit: ({formattedLimit}: ViolationsOverLimitParams) => `Expense exceeds auto approval limit of ${formattedLimit}`, diff --git a/src/languages/es.ts b/src/languages/es.ts index 55203ef32749..041160f9e0e5 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -86,6 +86,7 @@ import type { ViolationsInvoiceMarkupParams, ViolationsMaxAgeParams, ViolationsMissingTagParams, + ViolationsModifiedAmountParams, ViolationsOverAutoApprovalLimitParams, ViolationsOverCategoryLimitParams, ViolationsOverLimitParams, @@ -3460,7 +3461,19 @@ export default { missingCategory: 'Falta categoría', missingComment: 'Descripción obligatoria para la categoría seleccionada', missingTag: ({tagName}: ViolationsMissingTagParams) => `Falta ${tagName ?? 'etiqueta'}`, - modifiedAmount: 'Importe superior al del recibo escaneado', + modifiedAmount: ({type, displayPercentVariance}: ViolationsModifiedAmountParams) => { + if (type === 'card' && displayPercentVariance) { + return `Importe ${displayPercentVariance}% mayor al del recibo escaneado`; + } + switch (type) { + case 'distance': + return 'Importe difiere del calculado basado en distancia'; + case 'card': + return 'Importe mayor al de la transacción de la tarjeta'; + default: + return 'Importe mayor al del recibo escaneado'; + } + }, modifiedDate: 'Fecha difiere del recibo escaneado', nonExpensiworksExpense: 'Gasto no proviene de Expensiworks', overAutoApprovalLimit: ({formattedLimit}: ViolationsOverAutoApprovalLimitParams) => diff --git a/src/languages/types.ts b/src/languages/types.ts index e2e7e26e696b..665857c2efa5 100644 --- a/src/languages/types.ts +++ b/src/languages/types.ts @@ -222,6 +222,8 @@ type ViolationsMaxAgeParams = {maxAge: number}; type ViolationsMissingTagParams = {tagName?: string}; +type ViolationsModifiedAmountParams = {type: string; displayPercentVariance?: string}; + type ViolationsOverAutoApprovalLimitParams = {formattedLimit?: string}; type ViolationsOverCategoryLimitParams = {formattedLimit?: string}; @@ -382,6 +384,7 @@ export type { ViolationsInvoiceMarkupParams, ViolationsMaxAgeParams, ViolationsMissingTagParams, + ViolationsModifiedAmountParams, ViolationsOverAutoApprovalLimitParams, ViolationsOverCategoryLimitParams, ViolationsOverLimitParams, diff --git a/src/libs/Violations/ViolationsUtils.ts b/src/libs/Violations/ViolationsUtils.ts index 5e38d213edaa..c864747847d4 100644 --- a/src/libs/Violations/ViolationsUtils.ts +++ b/src/libs/Violations/ViolationsUtils.ts @@ -239,7 +239,7 @@ const ViolationsUtils = { case 'missingTag': return translate('violations.missingTag', {tagName}); case 'modifiedAmount': - return translate('violations.modifiedAmount'); + return translate('violations.modifiedAmount', {type: 'card'}); case 'modifiedDate': return translate('violations.modifiedDate'); case 'nonExpensiworksExpense': From 0549056529c2a89b7f765167eac237e107bf082b Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Fri, 10 May 2024 15:30:51 +0530 Subject: [PATCH 05/29] minor update. Signed-off-by: Krishna Gupta --- src/languages/en.ts | 6 +++--- src/languages/es.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 7faa4ed1804c..57082f98799e 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -2961,13 +2961,13 @@ export default { missingComment: 'Description required for selected category', missingTag: ({tagName}: ViolationsMissingTagParams) => `Missing ${tagName ?? 'tag'}`, modifiedAmount: ({type, displayPercentVariance}: ViolationsModifiedAmountParams): string => { - if (type === 'card' && displayPercentVariance) { - return `Amount ${displayPercentVariance}% greater than scanned receipt`; - } switch (type) { case 'distance': return 'Amount differs from calculated distance'; case 'card': + if (displayPercentVariance) { + return `Amount ${displayPercentVariance}% greater than scanned receipt`; + } return 'Amount greater than card transaction'; default: return 'Amount greater than scanned receipt'; diff --git a/src/languages/es.ts b/src/languages/es.ts index 041160f9e0e5..1eee82369f1a 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -3462,13 +3462,13 @@ export default { missingComment: 'Descripción obligatoria para la categoría seleccionada', missingTag: ({tagName}: ViolationsMissingTagParams) => `Falta ${tagName ?? 'etiqueta'}`, modifiedAmount: ({type, displayPercentVariance}: ViolationsModifiedAmountParams) => { - if (type === 'card' && displayPercentVariance) { - return `Importe ${displayPercentVariance}% mayor al del recibo escaneado`; - } switch (type) { case 'distance': return 'Importe difiere del calculado basado en distancia'; case 'card': + if (displayPercentVariance) { + return `Importe ${displayPercentVariance}% mayor al del recibo escaneado`; + } return 'Importe mayor al de la transacción de la tarjeta'; default: return 'Importe mayor al del recibo escaneado'; From f0390382c4788a3b1754caf32c28bd21d03bcab8 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Fri, 17 May 2024 13:43:59 +0530 Subject: [PATCH 06/29] remove taxAmountChanged & taxRateChanged notice violations. Signed-off-by: Krishna Gupta --- src/hooks/useViolations.ts | 5 ++++- src/languages/types.ts | 2 +- src/libs/Violations/ViolationsUtils.ts | 4 +++- src/types/onyx/TransactionViolation.ts | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/hooks/useViolations.ts b/src/hooks/useViolations.ts index 4f35c6d27a73..f5e53a06fb10 100644 --- a/src/hooks/useViolations.ts +++ b/src/hooks/useViolations.ts @@ -48,10 +48,13 @@ const violationFields: Record = { type ViolationsMap = Map; +// We don't want to show these violations on NewDot +const excludedViolationsName = ['taxAmountChanged', 'taxRateChanged']; + function useViolations(violations: TransactionViolation[], shouldIncludeNoticeViolations?: boolean) { const violationsByField = useMemo((): ViolationsMap => { const filteredViolations = violations.filter((violation) => { - if (violation.name === 'taxRateChanged' || violation.name === 'taxAmountChanged') { + if (excludedViolationsName.includes(violation.name)) { return false; } if (!shouldIncludeNoticeViolations) { diff --git a/src/languages/types.ts b/src/languages/types.ts index 665857c2efa5..c95e1043930d 100644 --- a/src/languages/types.ts +++ b/src/languages/types.ts @@ -222,7 +222,7 @@ type ViolationsMaxAgeParams = {maxAge: number}; type ViolationsMissingTagParams = {tagName?: string}; -type ViolationsModifiedAmountParams = {type: string; displayPercentVariance?: string}; +type ViolationsModifiedAmountParams = {type: string; displayPercentVariance?: number}; type ViolationsOverAutoApprovalLimitParams = {formattedLimit?: string}; diff --git a/src/libs/Violations/ViolationsUtils.ts b/src/libs/Violations/ViolationsUtils.ts index c864747847d4..edb351e8e155 100644 --- a/src/libs/Violations/ViolationsUtils.ts +++ b/src/libs/Violations/ViolationsUtils.ts @@ -239,7 +239,7 @@ const ViolationsUtils = { case 'missingTag': return translate('violations.missingTag', {tagName}); case 'modifiedAmount': - return translate('violations.modifiedAmount', {type: 'card'}); + return translate('violations.modifiedAmount', {type: violation.type, displayPercentVariance: violation.displayPercentVariance}); case 'modifiedDate': return translate('violations.modifiedDate'); case 'nonExpensiworksExpense': @@ -276,6 +276,8 @@ const ViolationsUtils = { return translate('violations.taxAmountChanged'); case 'taxOutOfPolicy': return translate('violations.taxOutOfPolicy', {taxName}); + case 'taxRateChanged': + return translate('violations.taxRateChanged'); case 'taxRequired': return translate('violations.taxRequired'); default: diff --git a/src/types/onyx/TransactionViolation.ts b/src/types/onyx/TransactionViolation.ts index ab2037ff336a..edb08b798683 100644 --- a/src/types/onyx/TransactionViolation.ts +++ b/src/types/onyx/TransactionViolation.ts @@ -31,6 +31,7 @@ type TransactionViolation = { errorIndexes?: number[]; pendingPattern?: boolean; }; + displayPercentVariance?: number; }; type TransactionViolations = TransactionViolation[]; From be4f9be6cf63214d701cb623463f2ef8ece6005e Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Mon, 3 Jun 2024 02:26:35 +0530 Subject: [PATCH 07/29] fix conflicts. Signed-off-by: Krishna Gupta --- .../ReportActionItem/MoneyRequestView.tsx | 62 +++++++++++-------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 7f47b504b481..f01fb049e943 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -7,7 +7,7 @@ import * as Expensicons from '@components/Icon/Expensicons'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; import {useSession} from '@components/OnyxProvider'; -import ReceiptAudit from '@components/ReceiptAudit'; +import {ReceiptAuditHeader, ReceiptAuditMessages} from '@components/ReceiptAudit'; import ReceiptEmptyState from '@components/ReceiptEmptyState'; import Switch from '@components/Switch'; import Text from '@components/Text'; @@ -15,12 +15,10 @@ import ViolationMessages from '@components/ViolationMessages'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import usePermissions from '@hooks/usePermissions'; -import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import useViolations from '@hooks/useViolations'; import type {ViolationField} from '@hooks/useViolations'; -import useWindowDimensions from '@hooks/useWindowDimensions'; import * as CardUtils from '@libs/CardUtils'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import type {MileageRate} from '@libs/DistanceRequestUtils'; @@ -29,6 +27,7 @@ import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as PolicyUtils from '@libs/PolicyUtils'; import {isTaxTrackingEnabled} from '@libs/PolicyUtils'; import * as ReceiptUtils from '@libs/ReceiptUtils'; +import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import ViolationsUtils from '@libs/Violations/ViolationsUtils'; @@ -97,9 +96,7 @@ function MoneyRequestView({ const theme = useTheme(); const styles = useThemeStyles(); const session = useSession(); - const StyleUtils = useStyleUtils(); const {isOffline} = useNetwork(); - const {isSmallScreenWidth} = useWindowDimensions(); const {translate, toLocaleDigit} = useLocalize(); const parentReportAction = parentReportActions?.[report.parentReportActionID ?? ''] ?? null; const isTrackExpense = ReportUtils.isTrackExpenseReport(report); @@ -129,6 +126,7 @@ function MoneyRequestView({ const cardProgramName = isCardTransaction && transactionCardID !== undefined ? CardUtils.getCardDescription(transactionCardID) : ''; const isApproved = ReportUtils.isReportApproved(moneyRequestReport); const isInvoice = ReportUtils.isInvoiceReport(moneyRequestReport); + const isPaidReport = ReportActionsUtils.isPayAction(parentReportAction); const taxRates = policy?.taxRates; const formattedTaxAmount = CurrencyUtils.convertToDisplayString(transactionTaxAmount, transactionCurrency); @@ -141,6 +139,8 @@ function MoneyRequestView({ // Used for non-restricted fields such as: description, category, tag, billable, etc. const canEdit = ReportUtils.canEditMoneyRequest(parentReportAction); + const canEditTaxFields = canEdit && !isDistanceRequest; + const canEditAmount = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.AMOUNT); const canEditMerchant = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.MERCHANT); const canEditDate = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DATE); @@ -148,8 +148,7 @@ function MoneyRequestView({ const hasReceipt = TransactionUtils.hasReceipt(transaction); const isReceiptBeingScanned = hasReceipt && TransactionUtils.isReceiptBeingScanned(transaction); const didRceiptScanSucceed = hasReceipt && TransactionUtils.didRceiptScanSucceed(transaction); - // TODO: remove the !isTrackExpense from this condition after this fix: https://github.com/Expensify/Expensify/issues/382786 - const canEditDistance = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DISTANCE) && !isTrackExpense; + const canEditDistance = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DISTANCE); const isAdmin = policy?.role === 'admin'; const isApprover = ReportUtils.isMoneyRequestReport(moneyRequestReport) && moneyRequestReport?.managerID !== null && session?.accountID === moneyRequestReport?.managerID; @@ -170,10 +169,9 @@ function MoneyRequestView({ const shouldShowTag = isPolicyExpenseChat && (transactionTag || OptionsListUtils.hasEnabledTags(policyTagLists)); const shouldShowBillable = isPolicyExpenseChat && (!!transactionBillable || !(policy?.disabledFields?.defaultBillable ?? true)); - // A flag for showing tax rate - const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy); + const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy, isDistanceRequest); - const {getViolationsForField} = useViolations(transactionViolations ?? [], !isReceiptBeingScanned && ReportUtils.isPaidGroupPolicy(report)); + const {getViolationsForField} = useViolations(transactionViolations ?? []); const hasViolations = useCallback( (field: ViolationField, data?: OnyxTypes.TransactionViolation['data']): boolean => !!canUseViolations && getViolationsForField(field, data).length > 0, [canUseViolations, getViolationsForField], @@ -318,19 +316,29 @@ function MoneyRequestView({ ); const shouldShowMapOrReceipt = showMapAsImage || hasReceipt; - const shouldShowReceiptEmptyState = !hasReceipt && !isInvoice && (canEditReceipt || isAdmin || isApprover); - const noticeTypeViolations = transactionViolations?.filter((violation) => violation.type === 'notice').map((v) => ViolationsUtils.getViolationTranslation(v, translate)) ?? []; - const shouldShowAuditMessage = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report); + const isReceiptAllowed = !isPaidReport && !isInvoice; + const shouldShowReceiptEmptyState = + isReceiptAllowed && !hasReceipt && !isApproved && !isSettled && (canEditReceipt || isAdmin || isApprover) && (canEditReceipt || ReportUtils.isPaidGroupPolicy(report)); + const receiptViolationNames: OnyxTypes.ViolationName[] = [ + CONST.VIOLATIONS.RECEIPT_REQUIRED, + CONST.VIOLATIONS.RECEIPT_NOT_SMART_SCANNED, + CONST.VIOLATIONS.MODIFIED_DATE, + CONST.VIOLATIONS.CASH_EXPENSE_WITH_NO_RECEIPT, + CONST.VIOLATIONS.SMARTSCAN_FAILED, + ]; + const receiptViolations = + transactionViolations?.filter((violation) => receiptViolationNames.includes(violation.name)).map((violation) => ViolationsUtils.getViolationTranslation(violation, translate)) ?? []; + const shouldShowNotesViolations = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report); + const shouldShowReceiptHeader = isReceiptAllowed && (shouldShowReceiptEmptyState || shouldShowMapOrReceipt) && canUseViolations && ReportUtils.isPaidGroupPolicy(report); return ( - + {shouldShowAnimatedBackground && } - - {!isInvoice && ( - + {shouldShowReceiptHeader && ( + )} {shouldShowMapOrReceipt && ( @@ -384,7 +392,7 @@ function MoneyRequestView({ /> )} {!shouldShowReceiptEmptyState && !shouldShowMapOrReceipt && } - {canUseViolations && } + {shouldShowNotesViolations && } Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_MERCHANT.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID ?? '', report.reportID)) } + wrapperStyle={[styles.taskDescriptionMenuItem]} brickRoadIndicator={getErrorForField('merchant') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined} errorText={getErrorForField('merchant')} + numberOfLinesTitle={0} /> )} @@ -504,8 +514,8 @@ function MoneyRequestView({ Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_TAX_RATE.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID ?? '', report.reportID)) @@ -521,8 +531,8 @@ function MoneyRequestView({ Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID ?? '', report.reportID)) @@ -551,7 +561,7 @@ function MoneyRequestView({ /> )} - + ); } From c9fd9aaff77b11e6f72ee14ad1472955b810fdbd Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Mon, 3 Jun 2024 02:29:07 +0530 Subject: [PATCH 08/29] fix conflicts. Signed-off-by: Krishna Gupta --- src/components/ReportActionItem/MoneyRequestView.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index f01fb049e943..014fd3c97096 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -7,7 +7,7 @@ import * as Expensicons from '@components/Icon/Expensicons'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; import {useSession} from '@components/OnyxProvider'; -import {ReceiptAuditHeader, ReceiptAuditMessages} from '@components/ReceiptAudit'; +import ReceiptAudit from '@components/ReceiptAudit'; import ReceiptEmptyState from '@components/ReceiptEmptyState'; import Switch from '@components/Switch'; import Text from '@components/Text'; @@ -171,7 +171,7 @@ function MoneyRequestView({ const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy, isDistanceRequest); - const {getViolationsForField} = useViolations(transactionViolations ?? []); + const {getViolationsForField} = useViolations(transactionViolations ?? [], !isReceiptBeingScanned && ReportUtils.isPaidGroupPolicy(report)); const hasViolations = useCallback( (field: ViolationField, data?: OnyxTypes.TransactionViolation['data']): boolean => !!canUseViolations && getViolationsForField(field, data).length > 0, [canUseViolations, getViolationsForField], @@ -328,7 +328,7 @@ function MoneyRequestView({ ]; const receiptViolations = transactionViolations?.filter((violation) => receiptViolationNames.includes(violation.name)).map((violation) => ViolationsUtils.getViolationTranslation(violation, translate)) ?? []; - const shouldShowNotesViolations = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report); + const shouldShowAuditMessage = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report); const shouldShowReceiptHeader = isReceiptAllowed && (shouldShowReceiptEmptyState || shouldShowMapOrReceipt) && canUseViolations && ReportUtils.isPaidGroupPolicy(report); return ( @@ -336,9 +336,10 @@ function MoneyRequestView({ {shouldShowAnimatedBackground && } <> {shouldShowReceiptHeader && ( - )} {shouldShowMapOrReceipt && ( @@ -392,7 +393,6 @@ function MoneyRequestView({ /> )} {!shouldShowReceiptEmptyState && !shouldShowMapOrReceipt && } - {shouldShowNotesViolations && } Date: Thu, 6 Jun 2024 09:52:39 +0530 Subject: [PATCH 09/29] use violation data type from backend. Signed-off-by: Krishna Gupta --- src/CONST.ts | 9 +++++++++ src/languages/types.ts | 3 ++- src/libs/Violations/ViolationsUtils.ts | 3 ++- src/types/onyx/TransactionViolation.ts | 4 +++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index a4c330b36cc6..a4fc07751c87 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3656,6 +3656,15 @@ const CONST = { WARNING: 'warning', }, + /** + * Constants for types of violation data. + */ + VIOLATION_DATA_TYPES: { + DISTANCE: 'distance', + CARD: 'card', + SMARTSCAN: 'smartscan', + }, + /** * Constants for types of violation names. * Defined here because they need to be referenced by the type system to generate the diff --git a/src/languages/types.ts b/src/languages/types.ts index c95e1043930d..7555fceba611 100644 --- a/src/languages/types.ts +++ b/src/languages/types.ts @@ -1,5 +1,6 @@ import type {ReportAction} from '@src/types/onyx'; import type {Unit} from '@src/types/onyx/Policy'; +import type {ViolationDataType} from '@src/types/onyx/TransactionViolation'; import type en from './en'; type AddressLineParams = { @@ -222,7 +223,7 @@ type ViolationsMaxAgeParams = {maxAge: number}; type ViolationsMissingTagParams = {tagName?: string}; -type ViolationsModifiedAmountParams = {type: string; displayPercentVariance?: number}; +type ViolationsModifiedAmountParams = {type?: ViolationDataType; displayPercentVariance?: number}; type ViolationsOverAutoApprovalLimitParams = {formattedLimit?: string}; diff --git a/src/libs/Violations/ViolationsUtils.ts b/src/libs/Violations/ViolationsUtils.ts index 13e6b52f56b4..9fc9ae93879b 100644 --- a/src/libs/Violations/ViolationsUtils.ts +++ b/src/libs/Violations/ViolationsUtils.ts @@ -202,6 +202,7 @@ const ViolationsUtils = { maxAge = 0, tagName, taxName, + type, } = violation.data ?? {}; switch (violation.name) { @@ -239,7 +240,7 @@ const ViolationsUtils = { case 'missingTag': return translate('violations.missingTag', {tagName}); case 'modifiedAmount': - return translate('violations.modifiedAmount', {type: violation.type, displayPercentVariance: violation.displayPercentVariance}); + return translate('violations.modifiedAmount', {type, displayPercentVariance: violation.displayPercentVariance}); case 'modifiedDate': return translate('violations.modifiedDate'); case 'nonExpensiworksExpense': diff --git a/src/types/onyx/TransactionViolation.ts b/src/types/onyx/TransactionViolation.ts index edb08b798683..6b905c17067a 100644 --- a/src/types/onyx/TransactionViolation.ts +++ b/src/types/onyx/TransactionViolation.ts @@ -5,6 +5,7 @@ import type CONST from '@src/CONST'; * Derived from `CONST.VIOLATIONS` to maintain a single source of truth. */ type ViolationName = (typeof CONST.VIOLATIONS)[keyof typeof CONST.VIOLATIONS]; +type ViolationDataType = (typeof CONST.VIOLATION_DATA_TYPES)[keyof typeof CONST.VIOLATION_DATA_TYPES]; type TransactionViolation = { type: string; @@ -30,11 +31,12 @@ type TransactionViolation = { tagListName?: string; errorIndexes?: number[]; pendingPattern?: boolean; + type?: ViolationDataType; }; displayPercentVariance?: number; }; type TransactionViolations = TransactionViolation[]; -export type {TransactionViolation, ViolationName}; +export type {TransactionViolation, ViolationName, ViolationDataType}; export default TransactionViolations; From 12f0433b475dab211725e4ce36202b67d8f17447 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Fri, 7 Jun 2024 11:14:48 +0530 Subject: [PATCH 10/29] add ViolationMessages for receipt. Signed-off-by: Krishna Gupta --- src/components/ReportActionItem/MoneyRequestView.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index d4aae74cc9b3..0512acb2eaff 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -402,6 +402,7 @@ function MoneyRequestView({ /> )} {!shouldShowReceiptEmptyState && !shouldShowMapOrReceipt && } + {canUseViolations && } Date: Fri, 7 Jun 2024 11:19:39 +0530 Subject: [PATCH 11/29] return all type of violations for paid policies. Signed-off-by: Krishna Gupta --- src/hooks/useViolations.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hooks/useViolations.ts b/src/hooks/useViolations.ts index e5a9824eaed6..938244f09eef 100644 --- a/src/hooks/useViolations.ts +++ b/src/hooks/useViolations.ts @@ -52,16 +52,16 @@ type ViolationsMap = Map; // We don't want to show these violations on NewDot const excludedViolationsName = ['taxAmountChanged', 'taxRateChanged']; -function useViolations(violations: TransactionViolation[], shouldIncludeNoticeViolations?: boolean) { +function useViolations(violations: TransactionViolation[], isPaidGroupPolicy?: boolean) { const violationsByField = useMemo((): ViolationsMap => { const filteredViolations = violations.filter((violation) => { if (excludedViolationsName.includes(violation.name)) { return false; } - if (!shouldIncludeNoticeViolations) { + if (!isPaidGroupPolicy) { return violation.type === CONST.VIOLATION_TYPES.VIOLATION; } - return violation.type === CONST.VIOLATION_TYPES.VIOLATION || violation.type === CONST.VIOLATION_TYPES.NOTICE; + return true; }); const violationGroups = new Map(); @@ -71,7 +71,7 @@ function useViolations(violations: TransactionViolation[], shouldIncludeNoticeVi violationGroups.set(field, [...existingViolations, violation]); } return violationGroups ?? new Map(); - }, [violations, shouldIncludeNoticeViolations]); + }, [violations, isPaidGroupPolicy]); const getViolationsForField = useCallback( (field: ViolationField, data?: TransactionViolation['data']) => { From 03a9345a1c1bcba1b5118f45cecfacf26b4ecefb Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Wed, 12 Jun 2024 15:28:39 +0530 Subject: [PATCH 12/29] add changes back in MoneyRequestView. Signed-off-by: Krishna Gupta --- .../ReportActionItem/MoneyRequestView.tsx | 14 +++++++------- src/types/onyx/TransactionViolation.ts | 11 ++++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index cc99a3f6e108..3029fa36da21 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -6,7 +6,7 @@ import * as Expensicons from '@components/Icon/Expensicons'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; import {useSession} from '@components/OnyxProvider'; -import {ReceiptAuditHeader, ReceiptAuditMessages} from '@components/ReceiptAudit'; +import ReceiptAudit from '@components/ReceiptAudit'; import ReceiptEmptyState from '@components/ReceiptEmptyState'; import Switch from '@components/Switch'; import Text from '@components/Text'; @@ -169,7 +169,7 @@ function MoneyRequestView({ const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy, isDistanceRequest); - const {getViolationsForField} = useViolations(transactionViolations ?? []); + const {getViolationsForField} = useViolations(transactionViolations ?? [], !isReceiptBeingScanned && ReportUtils.isPaidGroupPolicy(report)); const hasViolations = useCallback( (field: ViolationField, data?: OnyxTypes.TransactionViolation['data'], policyHasDependentTags = false, tagValue?: string): boolean => !!canUseViolations && getViolationsForField(field, data, policyHasDependentTags, tagValue).length > 0, @@ -326,7 +326,7 @@ function MoneyRequestView({ ]; const receiptViolations = transactionViolations?.filter((violation) => receiptViolationNames.includes(violation.name)).map((violation) => ViolationsUtils.getViolationTranslation(violation, translate)) ?? []; - const shouldShowNotesViolations = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report); + const shouldShowAuditMessage = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report); const shouldShowReceiptHeader = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt) && canUseViolations && ReportUtils.isPaidGroupPolicy(report); const errors = { @@ -370,9 +370,10 @@ function MoneyRequestView({ {shouldShowAnimatedBackground && } <> {shouldShowReceiptHeader && ( - )} {(hasReceipt || errors) && ( @@ -422,7 +423,7 @@ function MoneyRequestView({ /> )} {!shouldShowReceiptEmptyState && !hasReceipt && } - {shouldShowNotesViolations && } + {canUseViolations && }{' '} )} - {shouldShowTax && ( ; +/** + * Types of violation data. + * Derived from ONST.VIOLATION_DATA_TYPES` to maintain a single source of truth. + */ +type ViolationDataType = ValueOf; + /** Model of transaction violation data */ type TransactionViolationData = { /** Who rejected the transaction */ @@ -62,6 +68,9 @@ type TransactionViolationData = { /** Whether the current violation is `pending RTER` */ pendingPattern?: boolean; + + /** Violation data type */ + type?: ViolationDataType; }; /** Model of a transaction violation */ @@ -79,5 +88,5 @@ type TransactionViolation = { /** Collection of transaction violations */ type TransactionViolations = TransactionViolation[]; -export type {TransactionViolation, ViolationName}; +export type {TransactionViolation, ViolationName, ViolationDataType}; export default TransactionViolations; From 245d667e53a0fdd7046ec98efdcaa8dfe19ed366 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Wed, 12 Jun 2024 16:08:01 +0530 Subject: [PATCH 13/29] updated receiptViolationNames. Signed-off-by: Krishna Gupta --- src/components/ReportActionItem/MoneyRequestView.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 3029fa36da21..791e18d2af71 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -321,6 +321,7 @@ function MoneyRequestView({ CONST.VIOLATIONS.RECEIPT_REQUIRED, CONST.VIOLATIONS.RECEIPT_NOT_SMART_SCANNED, CONST.VIOLATIONS.MODIFIED_DATE, + CONST.VIOLATIONS.MODIFIED_AMOUNT, CONST.VIOLATIONS.CASH_EXPENSE_WITH_NO_RECEIPT, CONST.VIOLATIONS.SMARTSCAN_FAILED, ]; @@ -423,7 +424,7 @@ function MoneyRequestView({ /> )} {!shouldShowReceiptEmptyState && !hasReceipt && } - {canUseViolations && }{' '} + {canUseViolations && } Date: Thu, 13 Jun 2024 13:16:48 +0530 Subject: [PATCH 14/29] fix type check. Signed-off-by: Krishna Gupta --- src/types/onyx/TransactionViolation.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/types/onyx/TransactionViolation.ts b/src/types/onyx/TransactionViolation.ts index d77178104b72..0d8b94909631 100644 --- a/src/types/onyx/TransactionViolation.ts +++ b/src/types/onyx/TransactionViolation.ts @@ -83,6 +83,9 @@ type TransactionViolation = { /** Additional violation information to provide the user */ data?: TransactionViolationData; + + /** Percent Variance for modified amount violations */ + displayPercentVariance?: number; }; /** Collection of transaction violations */ From 9e452c4a13352c96de2641229f38eaab02049b8a Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Fri, 14 Jun 2024 16:10:19 +0530 Subject: [PATCH 15/29] minor fixes. Signed-off-by: Krishna Gupta --- src/components/ReceiptAudit.tsx | 2 +- src/languages/en.ts | 4 ++-- src/languages/es.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/ReceiptAudit.tsx b/src/components/ReceiptAudit.tsx index a5ccf543e0b7..b950e75c7b38 100644 --- a/src/components/ReceiptAudit.tsx +++ b/src/components/ReceiptAudit.tsx @@ -24,7 +24,7 @@ function ReceiptAudit({notes, shouldShowAuditSuccess, shouldShowAuditFailure}: { {translate('common.receipt')} - {auditText && ( + {!!auditText && ( <> {` • ${auditText}`} Date: Mon, 24 Jun 2024 00:31:55 +0530 Subject: [PATCH 16/29] fix lint issue. Signed-off-by: Krishna Gupta --- src/components/ReportActionItem/MoneyRequestView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 81efe2b89876..8e271973be3e 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -347,7 +347,7 @@ function MoneyRequestView({ ]; const receiptViolations = transactionViolations?.filter((violation) => receiptViolationNames.includes(violation.name)).map((violation) => ViolationsUtils.getViolationTranslation(violation, translate)) ?? []; - const shouldShowNotesViolations = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report); + const shouldShowAuditMessage = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report); const shouldShowReceiptHeader = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt); const errors = { From 7ae2d6b7b5b8672875f2106ffc5fecce9282a5f4 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Mon, 24 Jun 2024 00:55:23 +0530 Subject: [PATCH 17/29] get displayPercentVariance from violation data. Signed-off-by: Krishna Gupta --- src/libs/Violations/ViolationsUtils.ts | 2 +- src/types/onyx/TransactionViolation.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/Violations/ViolationsUtils.ts b/src/libs/Violations/ViolationsUtils.ts index 5ae16eb44d70..4db21993043f 100644 --- a/src/libs/Violations/ViolationsUtils.ts +++ b/src/libs/Violations/ViolationsUtils.ts @@ -289,7 +289,7 @@ const ViolationsUtils = { case 'missingTag': return translate('violations.missingTag', {tagName}); case 'modifiedAmount': - return translate('violations.modifiedAmount', {type, displayPercentVariance: violation.displayPercentVariance}); + return translate('violations.modifiedAmount', {type, displayPercentVariance: violation.data?.displayPercentVariance}); case 'modifiedDate': return translate('violations.modifiedDate'); case 'nonExpensiworksExpense': diff --git a/src/types/onyx/TransactionViolation.ts b/src/types/onyx/TransactionViolation.ts index d70e67ab06bc..7dd8b42335ed 100644 --- a/src/types/onyx/TransactionViolation.ts +++ b/src/types/onyx/TransactionViolation.ts @@ -72,6 +72,9 @@ type TransactionViolationData = { /** Violation data type */ type?: ViolationDataType; + /** Percent Variance for modified amount violations */ + displayPercentVariance?: number; + /** List of duplicate transactions */ duplicates?: string[]; }; @@ -86,9 +89,6 @@ type TransactionViolation = { /** Additional violation information to provide the user */ data?: TransactionViolationData; - - /** Percent Variance for modified amount violations */ - displayPercentVariance?: number; }; /** Collection of transaction violations */ From 1595f339f4ca46497319d8f2ff8d38ef25338225 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Fri, 5 Jul 2024 15:44:50 +0530 Subject: [PATCH 18/29] minor fixes. Signed-off-by: Krishna Gupta --- src/CONST.ts | 4 ++-- src/components/ReceiptAudit.tsx | 2 +- src/components/ReportActionItem/MoneyRequestView.tsx | 8 ++++---- src/types/onyx/TransactionViolation.ts | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 6df40bc754b7..c05eccfc1ae6 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3886,9 +3886,9 @@ const CONST = { }, /** - * Constants for types of violation data. + * Constants with different types for the modifiedAmount violation */ - VIOLATION_DATA_TYPES: { + MODIFIED_AMOUNT_VIOLATION_DATA: { DISTANCE: 'distance', CARD: 'card', SMARTSCAN: 'smartscan', diff --git a/src/components/ReceiptAudit.tsx b/src/components/ReceiptAudit.tsx index b950e75c7b38..a464497c4df2 100644 --- a/src/components/ReceiptAudit.tsx +++ b/src/components/ReceiptAudit.tsx @@ -7,7 +7,7 @@ import Icon from './Icon'; import * as Expensicons from './Icon/Expensicons'; import Text from './Text'; -function ReceiptAudit({notes, shouldShowAuditSuccess, shouldShowAuditFailure}: {notes: string[]; shouldShowAuditSuccess?: boolean; shouldShowAuditFailure?: boolean}) { +function ReceiptAudit({notes, shouldShowAuditSuccess, shouldShowAuditFailure}: {notes: string[]; shouldShowAuditSuccess: boolean; shouldShowAuditFailure: boolean}) { const styles = useThemeStyles(); const theme = useTheme(); const {translate} = useLocalize(); diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 87ffa274c295..914a23d780e3 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -348,7 +348,7 @@ function MoneyRequestView({ const receiptViolations = transactionViolations?.filter((violation) => receiptViolationNames.includes(violation.name)).map((violation) => ViolationsUtils.getViolationTranslation(violation, translate)) ?? []; const shouldShowAuditMessage = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report); - const shouldShowReceiptHeader = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt); + const shouldShowReceiptAudit = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt); const errors = { ...(transaction?.errorFields?.route ?? transaction?.errors), @@ -390,11 +390,11 @@ function MoneyRequestView({ {shouldShowAnimatedBackground && } <> - {shouldShowReceiptHeader && ( + {shouldShowReceiptAudit && ( )} {(hasReceipt || errors) && ( diff --git a/src/types/onyx/TransactionViolation.ts b/src/types/onyx/TransactionViolation.ts index 7dd8b42335ed..67497edd2f3a 100644 --- a/src/types/onyx/TransactionViolation.ts +++ b/src/types/onyx/TransactionViolation.ts @@ -8,10 +8,10 @@ import type CONST from '@src/CONST'; type ViolationName = ValueOf; /** - * Types of violation data. - * Derived from ONST.VIOLATION_DATA_TYPES` to maintain a single source of truth. + * Types for the data in the modifiedAmount violation + * Derived from CONST.VIOLATION_DATA_TYPES to maintain a single source of truth. */ -type ViolationDataType = ValueOf; +type ViolationDataType = ValueOf; /** Model of transaction violation data */ type TransactionViolationData = { @@ -69,7 +69,7 @@ type TransactionViolationData = { /** Whether the current violation is `pending RTER` */ pendingPattern?: boolean; - /** Violation data type */ + /** modifiedAmount violation type (eg, 'distance', 'card') */ type?: ViolationDataType; /** Percent Variance for modified amount violations */ From 2589ba6ee5b3d0b4ccbd195c792f5abaf4e05adf Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Fri, 5 Jul 2024 17:09:39 +0530 Subject: [PATCH 19/29] update isPaidGroupPolicy param to shouldShowOnlyViolations. Signed-off-by: Krishna Gupta --- src/components/ReportActionItem/MoneyRequestView.tsx | 2 +- src/hooks/useViolations.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 914a23d780e3..106297645a27 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -189,7 +189,7 @@ function MoneyRequestView({ const tripID = ReportUtils.getTripIDFromTransactionParentReport(parentReport); const shouldShowViewTripDetails = TransactionUtils.hasReservationList(transaction) && !!tripID; - const {getViolationsForField} = useViolations(transactionViolations ?? [], !isReceiptBeingScanned && ReportUtils.isPaidGroupPolicy(report)); + const {getViolationsForField} = useViolations(transactionViolations ?? [], !isReceiptBeingScanned || !ReportUtils.isPaidGroupPolicy(report)); const hasViolations = useCallback( (field: ViolationField, data?: OnyxTypes.TransactionViolation['data'], policyHasDependentTags = false, tagValue?: string): boolean => !!canUseViolations && getViolationsForField(field, data, policyHasDependentTags, tagValue).length > 0, diff --git a/src/hooks/useViolations.ts b/src/hooks/useViolations.ts index c348b9cc5ce5..491f1701d5c0 100644 --- a/src/hooks/useViolations.ts +++ b/src/hooks/useViolations.ts @@ -52,13 +52,17 @@ type ViolationsMap = Map; // We don't want to show these violations on NewDot const excludedViolationsName = ['taxAmountChanged', 'taxRateChanged']; -function useViolations(violations: TransactionViolation[], isPaidGroupPolicy?: boolean) { +/** + * @param violations – List of transaction violation + * @param shouldShowOnlyViolations – Whether we should only show violations of type 'violation + */ +function useViolations(violations: TransactionViolation[], shouldShowOnlyViolations: boolean) { const violationsByField = useMemo((): ViolationsMap => { const filteredViolations = violations.filter((violation) => { if (excludedViolationsName.includes(violation.name)) { return false; } - if (!isPaidGroupPolicy) { + if (shouldShowOnlyViolations) { return violation.type === CONST.VIOLATION_TYPES.VIOLATION; } return true; @@ -71,7 +75,7 @@ function useViolations(violations: TransactionViolation[], isPaidGroupPolicy?: b violationGroups.set(field, [...existingViolations, violation]); } return violationGroups ?? new Map(); - }, [violations, isPaidGroupPolicy]); + }, [violations, shouldShowOnlyViolations]); const getViolationsForField = useCallback( (field: ViolationField, data?: TransactionViolation['data'], policyHasDependentTags = false, tagValue?: string) => { From 6e63f5730f5121756e9cf3f5c1e0f0fc98b6c8b7 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Fri, 5 Jul 2024 17:41:15 +0530 Subject: [PATCH 20/29] add ReceiptAuditMessages back. Signed-off-by: Krishna Gupta --- src/components/ReceiptAudit.tsx | 6 ++++++ src/components/ReportActionItem/MoneyRequestView.tsx | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/ReceiptAudit.tsx b/src/components/ReceiptAudit.tsx index a464497c4df2..a1dc2a709d08 100644 --- a/src/components/ReceiptAudit.tsx +++ b/src/components/ReceiptAudit.tsx @@ -41,4 +41,10 @@ function ReceiptAudit({notes, shouldShowAuditSuccess, shouldShowAuditFailure}: { ); } +function ReceiptAuditMessages({notes = []}: {notes?: string[]}) { + const styles = useThemeStyles(); + return {notes.length > 0 && notes.map((message) => {message})}; +} + +export {ReceiptAuditMessages}; export default ReceiptAudit; diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 106297645a27..0743e151c202 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -7,7 +7,7 @@ import MenuItem from '@components/MenuItem'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; import {useSession} from '@components/OnyxProvider'; -import ReceiptAudit from '@components/ReceiptAudit'; +import ReceiptAudit, {ReceiptAuditMessages} from '@components/ReceiptAudit'; import ReceiptEmptyState from '@components/ReceiptEmptyState'; import Switch from '@components/Switch'; import Text from '@components/Text'; @@ -450,7 +450,7 @@ function MoneyRequestView({ /> )} {!shouldShowReceiptEmptyState && !hasReceipt && } - {canUseViolations && } + {shouldShowAuditMessage && } Date: Sat, 6 Jul 2024 03:40:51 +0530 Subject: [PATCH 21/29] add comments. Signed-off-by: Krishna Gupta --- src/components/ReceiptAudit.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/ReceiptAudit.tsx b/src/components/ReceiptAudit.tsx index a1dc2a709d08..2fadf4f95274 100644 --- a/src/components/ReceiptAudit.tsx +++ b/src/components/ReceiptAudit.tsx @@ -7,13 +7,23 @@ import Icon from './Icon'; import * as Expensicons from './Icon/Expensicons'; import Text from './Text'; -function ReceiptAudit({notes, shouldShowAuditSuccess, shouldShowAuditFailure}: {notes: string[]; shouldShowAuditSuccess: boolean; shouldShowAuditFailure: boolean}) { +type ReceiptAuditPropsType = { + /** List of audit notes */ + notes: string[]; + + /** Weather to show success message (e.g. When receipt is scanning, we don't want to show `Verified` message) */ + shouldShowAuditSuccess: boolean; + + /** Weather to show failure message (e.g. When receipt isn't required, we don't want to show `Issues Found` message) */ + shouldShowAuditFailure: boolean; +}; + +function ReceiptAudit({notes, shouldShowAuditSuccess, shouldShowAuditFailure}: ReceiptAuditPropsType) { const styles = useThemeStyles(); const theme = useTheme(); const {translate} = useLocalize(); let auditText = ''; - if (notes.length > 0 && shouldShowAuditFailure) { auditText = translate('iou.receiptIssuesFound', notes.length); } else if (!notes.length && shouldShowAuditSuccess) { From 68ebaa75250cf31dacaff587f8d0a4038c8f68d3 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 9 Jul 2024 03:32:17 +0530 Subject: [PATCH 22/29] update comments. Signed-off-by: krishna2323 --- src/components/ReceiptAudit.tsx | 4 ++-- src/hooks/useViolations.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/ReceiptAudit.tsx b/src/components/ReceiptAudit.tsx index 2fadf4f95274..69e5b8a03225 100644 --- a/src/components/ReceiptAudit.tsx +++ b/src/components/ReceiptAudit.tsx @@ -7,7 +7,7 @@ import Icon from './Icon'; import * as Expensicons from './Icon/Expensicons'; import Text from './Text'; -type ReceiptAuditPropsType = { +type ReceiptAuditProps = { /** List of audit notes */ notes: string[]; @@ -18,7 +18,7 @@ type ReceiptAuditPropsType = { shouldShowAuditFailure: boolean; }; -function ReceiptAudit({notes, shouldShowAuditSuccess, shouldShowAuditFailure}: ReceiptAuditPropsType) { +function ReceiptAudit({notes, shouldShowAuditSuccess, shouldShowAuditFailure}: ReceiptAuditProps) { const styles = useThemeStyles(); const theme = useTheme(); const {translate} = useLocalize(); diff --git a/src/hooks/useViolations.ts b/src/hooks/useViolations.ts index 491f1701d5c0..44b8e982139e 100644 --- a/src/hooks/useViolations.ts +++ b/src/hooks/useViolations.ts @@ -53,8 +53,8 @@ type ViolationsMap = Map; const excludedViolationsName = ['taxAmountChanged', 'taxRateChanged']; /** - * @param violations – List of transaction violation - * @param shouldShowOnlyViolations – Whether we should only show violations of type 'violation + * @param violations – List of transaction violations + * @param shouldShowOnlyViolations – Whether we should only show violations of type 'violation' */ function useViolations(violations: TransactionViolation[], shouldShowOnlyViolations: boolean) { const violationsByField = useMemo((): ViolationsMap => { From 2a7637739ce7aba8574e8e33ea2dbea321e62739 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 9 Jul 2024 03:34:52 +0530 Subject: [PATCH 23/29] minor update. Signed-off-by: krishna2323 --- src/components/ReportActionItem/MoneyRequestView.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 0743e151c202..905d42117e36 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -347,7 +347,7 @@ function MoneyRequestView({ ]; const receiptViolations = transactionViolations?.filter((violation) => receiptViolationNames.includes(violation.name)).map((violation) => ViolationsUtils.getViolationTranslation(violation, translate)) ?? []; - const shouldShowAuditMessage = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report); + const shouldShowAuditMessage = !isReceiptBeingScanned && !!canUseViolations && ReportUtils.isPaidGroupPolicy(report); const shouldShowReceiptAudit = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt); const errors = { @@ -393,8 +393,8 @@ function MoneyRequestView({ {shouldShowReceiptAudit && ( )} {(hasReceipt || errors) && ( From c5d5a3c9d1ac58f7de457f214822ee434b711b97 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 9 Jul 2024 03:58:11 +0530 Subject: [PATCH 24/29] fix: amount violation shows under receipt. Signed-off-by: krishna2323 --- src/components/ReportActionItem/MoneyRequestView.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 905d42117e36..0be4b77f9749 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -340,8 +340,6 @@ function MoneyRequestView({ const receiptViolationNames: OnyxTypes.ViolationName[] = [ CONST.VIOLATIONS.RECEIPT_REQUIRED, CONST.VIOLATIONS.RECEIPT_NOT_SMART_SCANNED, - CONST.VIOLATIONS.MODIFIED_DATE, - CONST.VIOLATIONS.MODIFIED_AMOUNT, CONST.VIOLATIONS.CASH_EXPENSE_WITH_NO_RECEIPT, CONST.VIOLATIONS.SMARTSCAN_FAILED, ]; From 995eaed07c9777e4359a92ed2f040bacefe818a8 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 9 Jul 2024 04:45:59 +0530 Subject: [PATCH 25/29] fix amount violation not showing. Signed-off-by: krishna2323 --- src/components/ReportActionItem/MoneyRequestView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 0be4b77f9749..ffc101d96df9 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -189,7 +189,7 @@ function MoneyRequestView({ const tripID = ReportUtils.getTripIDFromTransactionParentReport(parentReport); const shouldShowViewTripDetails = TransactionUtils.hasReservationList(transaction) && !!tripID; - const {getViolationsForField} = useViolations(transactionViolations ?? [], !isReceiptBeingScanned || !ReportUtils.isPaidGroupPolicy(report)); + const {getViolationsForField} = useViolations(transactionViolations ?? [], isReceiptBeingScanned || !ReportUtils.isPaidGroupPolicy(report)); const hasViolations = useCallback( (field: ViolationField, data?: OnyxTypes.TransactionViolation['data'], policyHasDependentTags = false, tagValue?: string): boolean => !!canUseViolations && getViolationsForField(field, data, policyHasDependentTags, tagValue).length > 0, From e3b692e1f6b0c8cee0734ac6dcc7fe7836b98d47 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Wed, 10 Jul 2024 19:51:37 +0530 Subject: [PATCH 26/29] remove shouldShowAuditSuccess & shouldShowAuditFailure prop. Signed-off-by: krishna2323 --- src/components/ReceiptAudit.tsx | 12 +++--------- .../ReportActionItem/MoneyRequestView.tsx | 15 +++++++-------- src/libs/TransactionUtils.ts | 5 +++++ 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/components/ReceiptAudit.tsx b/src/components/ReceiptAudit.tsx index 69e5b8a03225..098a4e68608d 100644 --- a/src/components/ReceiptAudit.tsx +++ b/src/components/ReceiptAudit.tsx @@ -10,23 +10,17 @@ import Text from './Text'; type ReceiptAuditProps = { /** List of audit notes */ notes: string[]; - - /** Weather to show success message (e.g. When receipt is scanning, we don't want to show `Verified` message) */ - shouldShowAuditSuccess: boolean; - - /** Weather to show failure message (e.g. When receipt isn't required, we don't want to show `Issues Found` message) */ - shouldShowAuditFailure: boolean; }; -function ReceiptAudit({notes, shouldShowAuditSuccess, shouldShowAuditFailure}: ReceiptAuditProps) { +function ReceiptAudit({notes}: ReceiptAuditProps) { const styles = useThemeStyles(); const theme = useTheme(); const {translate} = useLocalize(); let auditText = ''; - if (notes.length > 0 && shouldShowAuditFailure) { + if (notes.length > 0) { auditText = translate('iou.receiptIssuesFound', notes.length); - } else if (!notes.length && shouldShowAuditSuccess) { + } else if (!notes.length) { auditText = translate('common.verified'); } diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index ffc101d96df9..ac5f54a0a9a7 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -164,6 +164,7 @@ function MoneyRequestView({ const hasReceipt = TransactionUtils.hasReceipt(transaction); const isReceiptBeingScanned = hasReceipt && TransactionUtils.isReceiptBeingScanned(transaction); const didRceiptScanSucceed = hasReceipt && TransactionUtils.didRceiptScanSucceed(transaction); + const isRceiptStateOpen = hasReceipt && TransactionUtils.isRceiptStateOpen(transaction); const canEditDistance = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DISTANCE); const isAdmin = policy?.role === 'admin'; @@ -343,7 +344,7 @@ function MoneyRequestView({ CONST.VIOLATIONS.CASH_EXPENSE_WITH_NO_RECEIPT, CONST.VIOLATIONS.SMARTSCAN_FAILED, ]; - const receiptViolations = + let receiptViolations = transactionViolations?.filter((violation) => receiptViolationNames.includes(violation.name)).map((violation) => ViolationsUtils.getViolationTranslation(violation, translate)) ?? []; const shouldShowAuditMessage = !isReceiptBeingScanned && !!canUseViolations && ReportUtils.isPaidGroupPolicy(report); const shouldShowReceiptAudit = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt); @@ -384,17 +385,15 @@ function MoneyRequestView({ ); }); + if (!shouldShowAuditMessage || !hasReceipt || (!didRceiptScanSucceed && !isRceiptStateOpen)) { + receiptViolations = []; + } + return ( {shouldShowAnimatedBackground && } <> - {shouldShowReceiptAudit && ( - - )} + {shouldShowReceiptAudit && } {(hasReceipt || errors) && ( ): boolean { return [CONST.IOU.RECEIPT_STATE.SCANCOMPLETE].some((value) => value === transaction?.receipt?.state); } +function isRceiptStateOpen(transaction: OnyxEntry): boolean { + return CONST.IOU.RECEIPT_STATE.OPEN === transaction?.receipt?.state; +} + /** * Check if the transaction has a non-smartscanning receipt and is missing required fields */ @@ -951,6 +955,7 @@ export { hasRoute, isReceiptBeingScanned, didRceiptScanSucceed, + isRceiptStateOpen, getValidWaypoints, isDistanceRequest, isFetchingWaypointsFromServer, From 0a92c99fe8b7842711d289b7896dc54ac7101cf1 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Sat, 13 Jul 2024 02:50:05 +0530 Subject: [PATCH 27/29] add shouldShowAuditResult prop in ReceiptAudit. Signed-off-by: krishna2323 --- src/components/ReceiptAudit.tsx | 9 ++++++--- .../ReportActionItem/MoneyRequestView.tsx | 13 +++++++++---- src/libs/TransactionUtils.ts | 8 ++++---- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/components/ReceiptAudit.tsx b/src/components/ReceiptAudit.tsx index 098a4e68608d..bb704def1836 100644 --- a/src/components/ReceiptAudit.tsx +++ b/src/components/ReceiptAudit.tsx @@ -10,17 +10,20 @@ import Text from './Text'; type ReceiptAuditProps = { /** List of audit notes */ notes: string[]; + + /** Whether to show audit result or not (e.g.`Verified`, `Issue Found`) */ + shouldShowAuditResult: boolean; }; -function ReceiptAudit({notes}: ReceiptAuditProps) { +function ReceiptAudit({notes, shouldShowAuditResult}: ReceiptAuditProps) { const styles = useThemeStyles(); const theme = useTheme(); const {translate} = useLocalize(); let auditText = ''; - if (notes.length > 0) { + if (notes.length > 0 && shouldShowAuditResult) { auditText = translate('iou.receiptIssuesFound', notes.length); - } else if (!notes.length) { + } else if (!notes.length && shouldShowAuditResult) { auditText = translate('common.verified'); } diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index ac5f54a0a9a7..3d8641ff49fa 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -163,8 +163,8 @@ function MoneyRequestView({ const canEditReceipt = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.RECEIPT); const hasReceipt = TransactionUtils.hasReceipt(transaction); const isReceiptBeingScanned = hasReceipt && TransactionUtils.isReceiptBeingScanned(transaction); - const didRceiptScanSucceed = hasReceipt && TransactionUtils.didRceiptScanSucceed(transaction); - const isRceiptStateOpen = hasReceipt && TransactionUtils.isRceiptStateOpen(transaction); + const didReceiptScanSucceed = hasReceipt && TransactionUtils.didReceiptScanSucceed(transaction); + const isReceiptStateOpen = hasReceipt && TransactionUtils.isReceiptStateOpen(transaction); const canEditDistance = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DISTANCE); const isAdmin = policy?.role === 'admin'; @@ -385,7 +385,7 @@ function MoneyRequestView({ ); }); - if (!shouldShowAuditMessage || !hasReceipt || (!didRceiptScanSucceed && !isRceiptStateOpen)) { + if (!shouldShowAuditMessage || !hasReceipt || (!didReceiptScanSucceed && !isReceiptStateOpen)) { receiptViolations = []; } @@ -393,7 +393,12 @@ function MoneyRequestView({ {shouldShowAnimatedBackground && } <> - {shouldShowReceiptAudit && } + {shouldShowReceiptAudit && ( + + )} {(hasReceipt || errors) && ( ): bool return [CONST.IOU.RECEIPT_STATE.SCANREADY, CONST.IOU.RECEIPT_STATE.SCANNING].some((value) => value === transaction?.receipt?.state); } -function didRceiptScanSucceed(transaction: OnyxEntry): boolean { +function didReceiptScanSucceed(transaction: OnyxEntry): boolean { return [CONST.IOU.RECEIPT_STATE.SCANCOMPLETE].some((value) => value === transaction?.receipt?.state); } -function isRceiptStateOpen(transaction: OnyxEntry): boolean { +function isReceiptStateOpen(transaction: OnyxEntry): boolean { return CONST.IOU.RECEIPT_STATE.OPEN === transaction?.receipt?.state; } @@ -954,8 +954,8 @@ export { hasEReceipt, hasRoute, isReceiptBeingScanned, - didRceiptScanSucceed, - isRceiptStateOpen, + didReceiptScanSucceed, + isReceiptStateOpen, getValidWaypoints, isDistanceRequest, isFetchingWaypointsFromServer, From 1c4d2a1011a29fc47a3e9121a77ec774288b910f Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Sat, 13 Jul 2024 03:07:22 +0530 Subject: [PATCH 28/29] refactor. Signed-off-by: krishna2323 --- src/components/ReportActionItem/MoneyRequestView.tsx | 12 ++++-------- src/libs/TransactionUtils.ts | 5 ----- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 3d8641ff49fa..5c0e91591e2f 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -164,7 +164,6 @@ function MoneyRequestView({ const hasReceipt = TransactionUtils.hasReceipt(transaction); const isReceiptBeingScanned = hasReceipt && TransactionUtils.isReceiptBeingScanned(transaction); const didReceiptScanSucceed = hasReceipt && TransactionUtils.didReceiptScanSucceed(transaction); - const isReceiptStateOpen = hasReceipt && TransactionUtils.isReceiptStateOpen(transaction); const canEditDistance = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DISTANCE); const isAdmin = policy?.role === 'admin'; @@ -344,9 +343,10 @@ function MoneyRequestView({ CONST.VIOLATIONS.CASH_EXPENSE_WITH_NO_RECEIPT, CONST.VIOLATIONS.SMARTSCAN_FAILED, ]; - let receiptViolations = + const receiptViolations = transactionViolations?.filter((violation) => receiptViolationNames.includes(violation.name)).map((violation) => ViolationsUtils.getViolationTranslation(violation, translate)) ?? []; - const shouldShowAuditMessage = !isReceiptBeingScanned && !!canUseViolations && ReportUtils.isPaidGroupPolicy(report); + const shouldShowAuditMessage = + !isReceiptBeingScanned && hasReceipt && !!(receiptViolations.length || didReceiptScanSucceed) && !!canUseViolations && ReportUtils.isPaidGroupPolicy(report); const shouldShowReceiptAudit = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt); const errors = { @@ -385,10 +385,6 @@ function MoneyRequestView({ ); }); - if (!shouldShowAuditMessage || !hasReceipt || (!didReceiptScanSucceed && !isReceiptStateOpen)) { - receiptViolations = []; - } - return ( {shouldShowAnimatedBackground && } @@ -396,7 +392,7 @@ function MoneyRequestView({ {shouldShowReceiptAudit && ( )} {(hasReceipt || errors) && ( diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index dfba4989435b..24b7c4ef91f2 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -531,10 +531,6 @@ function didReceiptScanSucceed(transaction: OnyxEntry): boolean { return [CONST.IOU.RECEIPT_STATE.SCANCOMPLETE].some((value) => value === transaction?.receipt?.state); } -function isReceiptStateOpen(transaction: OnyxEntry): boolean { - return CONST.IOU.RECEIPT_STATE.OPEN === transaction?.receipt?.state; -} - /** * Check if the transaction has a non-smartscanning receipt and is missing required fields */ @@ -955,7 +951,6 @@ export { hasRoute, isReceiptBeingScanned, didReceiptScanSucceed, - isReceiptStateOpen, getValidWaypoints, isDistanceRequest, isFetchingWaypointsFromServer, From 7cdc36c51898042907464a6f1dd09dd4e65739d3 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Sat, 13 Jul 2024 03:11:04 +0530 Subject: [PATCH 29/29] add comment. Signed-off-by: krishna2323 --- src/components/ReportActionItem/MoneyRequestView.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 5c0e91591e2f..bcd255255bb0 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -345,6 +345,9 @@ function MoneyRequestView({ ]; const receiptViolations = transactionViolations?.filter((violation) => receiptViolationNames.includes(violation.name)).map((violation) => ViolationsUtils.getViolationTranslation(violation, translate)) ?? []; + + // Whether to show receipt audit result (e.g.`Verified`, `Issue Found`) and messages (e.g. `Receipt not verified. Please confirm accuracy.`) + // `!!(receiptViolations.length || didReceiptScanSucceed)` is for not showing `Verified` when `receiptViolations` is empty and `didReceiptScanSucceed` is false. const shouldShowAuditMessage = !isReceiptBeingScanned && hasReceipt && !!(receiptViolations.length || didReceiptScanSucceed) && !!canUseViolations && ReportUtils.isPaidGroupPolicy(report); const shouldShowReceiptAudit = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt);