Skip to content

Commit 1ff4def

Browse files
authored
Merge pull request Expensify#77836 from Expensify/cmartins-taxRate
Add tax rate
2 parents 0bc2b57 + 305da9f commit 1ff4def

6 files changed

Lines changed: 58 additions & 5 deletions

File tree

src/CONST/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6705,6 +6705,8 @@ const CONST = {
67056705
BASE_62_REPORT_ID: this.TABLE_COLUMNS.BASE_62_REPORT_ID,
67066706
REIMBURSABLE: this.TABLE_COLUMNS.REIMBURSABLE,
67076707
BILLABLE: this.TABLE_COLUMNS.BILLABLE,
6708+
TAX_RATE: this.TABLE_COLUMNS.TAX_RATE,
6709+
TAX_AMOUNT: this.TABLE_COLUMNS.TAX_AMOUNT,
67086710
STATUS: this.TABLE_COLUMNS.STATUS,
67096711
TITLE: this.TABLE_COLUMNS.TITLE,
67106712
ACTION: this.TABLE_COLUMNS.ACTION,
@@ -6804,6 +6806,7 @@ const CONST = {
68046806
ORIGINAL_AMOUNT: 'originalamount',
68056807
REIMBURSABLE: 'reimbursable',
68066808
BILLABLE: 'billable',
6809+
TAX_RATE: 'taxrate',
68076810
TOTAL_AMOUNT: 'amount',
68086811
TOTAL: 'total',
68096812
TYPE: 'type',

src/components/SelectionListWithSections/SearchTableHeader.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,14 @@ const getExpenseHeaders = (groupBy?: SearchGroupBy): SearchColumnConfig[] => [
9898
columnName: CONST.SEARCH.TABLE_COLUMNS.WITHDRAWAL_ID,
9999
translationKey: 'common.withdrawalID',
100100
},
101+
{
102+
columnName: CONST.SEARCH.TABLE_COLUMNS.TAX_RATE,
103+
translationKey: 'iou.taxRate',
104+
canBeMissing: true,
105+
},
101106
{
102107
columnName: CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT,
103108
translationKey: 'common.tax',
104-
isColumnSortable: false,
105109
canBeMissing: true,
106110
},
107111
{

src/components/SelectionListWithSections/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ type TransactionListItemType = ListItem &
338338

339339
/** The main action that can be performed for the transaction */
340340
action: SearchTransactionAction;
341+
342+
/** The tax code of the transaction */
343+
taxCode?: string;
341344
};
342345

343346
type ReportActionListItemType = ListItem &

src/components/TransactionItemRow/index.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
} from '@libs/TransactionUtils';
3939
import CONST from '@src/CONST';
4040
import type {TranslationPaths} from '@src/languages/types';
41-
import type {PersonalDetails, Report, TransactionViolation} from '@src/types/onyx';
41+
import type {PersonalDetails, Policy, Report, TransactionViolation} from '@src/types/onyx';
4242
import type {SearchTransactionAction} from '@src/types/onyx/SearchResults';
4343
import CategoryCell from './DataCells/CategoryCell';
4444
import ChatBubbleCell from './DataCells/ChatBubbleCell';
@@ -86,6 +86,9 @@ type TransactionWithOptionalSearchFields = TransactionWithOptionalHighlight & {
8686

8787
/** Report to which the transaction belongs */
8888
report?: Report;
89+
90+
/** Policy to which the transaction belongs */
91+
policy?: Policy;
8992
};
9093

9194
type TransactionItemRowProps = {
@@ -190,6 +193,21 @@ function TransactionItemRow({
190193
const merchant = useMemo(() => getMerchantName(transactionItem, translate), [transactionItem, translate]);
191194
const description = getDescription(transactionItem);
192195

196+
const formattedTaxRate = useMemo(() => {
197+
const taxRateName = transactionItem?.policy?.taxRates?.taxes?.[transactionItem.taxCode ?? '']?.name ?? '';
198+
const taxRateValue = transactionItem?.policy?.taxRates?.taxes?.[transactionItem.taxCode ?? '']?.value ?? '';
199+
200+
if (!taxRateName && !taxRateValue) {
201+
return '';
202+
}
203+
204+
if (!taxRateValue) {
205+
return taxRateName;
206+
}
207+
208+
return `${taxRateName} (${taxRateValue})`;
209+
}, [transactionItem?.policy?.taxRates?.taxes, transactionItem.taxCode]);
210+
193211
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
194212
const merchantOrDescription = merchant || description;
195213

@@ -454,9 +472,17 @@ function TransactionItemRow({
454472
<TextCell text={transactionItem.reportID === CONST.REPORT.UNREPORTED_REPORT_ID ? '' : getBase62ReportID(Number(transactionItem.reportID))} />
455473
</View>
456474
),
457-
[CONST.SEARCH.TABLE_COLUMNS.TAX]: (
475+
[CONST.SEARCH.TABLE_COLUMNS.TAX_RATE]: (
476+
<View
477+
key={CONST.SEARCH.TABLE_COLUMNS.TAX_RATE}
478+
style={[StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.TAX_RATE)]}
479+
>
480+
<TextCell text={formattedTaxRate} />
481+
</View>
482+
),
483+
[CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT]: (
458484
<View
459-
key={CONST.SEARCH.TABLE_COLUMNS.TAX}
485+
key={CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT}
460486
style={[StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT, undefined, undefined, isTaxAmountColumnWide)]}
461487
>
462488
<TaxCell
@@ -508,6 +534,7 @@ function TransactionItemRow({
508534
isAmountColumnWide,
509535
isTaxAmountColumnWide,
510536
isLargeScreenWidth,
537+
formattedTaxRate,
511538
],
512539
);
513540
const shouldRenderChatBubbleCell = useMemo(() => {

src/libs/SearchUIUtils.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ const transactionColumnNamesToSortingProperty: TransactionSorting = {
151151
[CONST.SEARCH.TABLE_COLUMNS.TYPE]: null,
152152
[CONST.SEARCH.TABLE_COLUMNS.ACTION]: 'action' as const,
153153
[CONST.SEARCH.TABLE_COLUMNS.DESCRIPTION]: 'comment' as const,
154-
[CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT]: null,
154+
[CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT]: 'taxAmount' as const,
155155
[CONST.SEARCH.TABLE_COLUMNS.RECEIPT]: null,
156156
};
157157

@@ -2076,6 +2076,14 @@ function getSortedTransactionData(
20762076
});
20772077
}
20782078

2079+
if (sortBy === CONST.SEARCH.TABLE_COLUMNS.TAX_RATE) {
2080+
return data.sort((a, b) => {
2081+
const aValue = `${a.policy?.taxRates?.taxes?.[a.taxCode ?? '']?.name ?? ''} (${a.policy?.taxRates?.taxes?.[a.taxCode ?? '']?.value ?? ''})`;
2082+
const bValue = `${b.policy?.taxRates?.taxes?.[b.taxCode ?? '']?.name ?? ''} (${b.policy?.taxRates?.taxes?.[b.taxCode ?? '']?.value ?? ''})`;
2083+
return compareValues(aValue, bValue, sortOrder, sortBy, localeCompare);
2084+
});
2085+
}
2086+
20792087
if (!sortingProperty) {
20802088
return data;
20812089
}
@@ -2318,6 +2326,10 @@ function getSearchColumnTranslationKey(columnId: SearchCustomColumnIds): Transla
23182326
return 'common.title';
23192327
case CONST.SEARCH.TABLE_COLUMNS.STATUS:
23202328
return 'common.status';
2329+
case CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT:
2330+
return 'common.tax';
2331+
case CONST.SEARCH.TABLE_COLUMNS.TAX_RATE:
2332+
return 'iou.taxRate';
23212333
case CONST.SEARCH.TABLE_COLUMNS.REPORT_ID:
23222334
return 'common.longID';
23232335
case CONST.SEARCH.TABLE_COLUMNS.BASE_62_REPORT_ID:
@@ -2785,6 +2797,7 @@ function getColumnsToShow(
27852797
[CONST.SEARCH.TABLE_COLUMNS.TAG]: false,
27862798
[CONST.SEARCH.TABLE_COLUMNS.REIMBURSABLE]: false,
27872799
[CONST.SEARCH.TABLE_COLUMNS.BILLABLE]: false,
2800+
[CONST.SEARCH.TABLE_COLUMNS.TAX_RATE]: false,
27882801
[CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT]: false,
27892802
[CONST.SEARCH.TABLE_COLUMNS.ORIGINAL_AMOUNT]: false,
27902803
[CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT]: true,

src/styles/utils/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,9 @@ const createStyleUtils = (theme: ThemeColors, styles: ThemeStyles) => ({
17761776
case CONST.SEARCH.TABLE_COLUMNS.BILLABLE:
17771777
columnWidth = {...getWidthStyle(variables.w92)};
17781778
break;
1779+
case CONST.SEARCH.TABLE_COLUMNS.TAX_RATE:
1780+
columnWidth = {...getWidthStyle(variables.w92), ...styles.flex1};
1781+
break;
17791782
case CONST.SEARCH.TABLE_COLUMNS.ACTION:
17801783
columnWidth = {...getWidthStyle(variables.w80), ...styles.alignItemsCenter};
17811784
break;

0 commit comments

Comments
 (0)