Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ import {
getTagArrayFromName,
getTagForDisplay,
getTaxName,
getTaxValue,
hasMissingSmartscanFields,
hasMultipleSplitChildren,
hasReservationList,
Expand Down Expand Up @@ -306,12 +305,7 @@ function MoneyRequestView({
: convertToDisplayString(Math.abs(transactionTaxAmount ?? 0), actualCurrency);

const taxRatesDescription = taxRates?.name;

const baseTransaction = updatedTransaction ?? transaction;
const {taxCode, taxValue} = baseTransaction ?? {};

const taxRateTitle = taxCode ? getTaxName(policy, baseTransaction, isExpenseUnreported) : '';
const hasTaxValueChanged = taxCode ? getTaxValue(policy, baseTransaction, taxCode) !== baseTransaction?.taxValue : false;
const taxRateTitle = updatedTransaction ? getTaxName(policy, updatedTransaction, isExpenseUnreported) : getTaxName(policy, transaction, isExpenseUnreported);

const actualTransactionDate = isFromMergeTransaction && updatedTransaction ? getFormattedCreated(updatedTransaction) : transactionDate;
const fallbackTaxRateTitle = transaction?.taxValue;
Expand Down Expand Up @@ -598,7 +592,7 @@ function MoneyRequestView({
const decodedCategoryName = getDecodedCategoryName(categoryValue);
const categoryCopyValue = !canEdit ? decodedCategoryName : undefined;
const cardCopyValue = cardProgramName;
const taxRateValue = hasTaxValueChanged ? taxValue : (transaction?.taxName ?? taxRateTitle ?? fallbackTaxRateTitle ?? '');
const taxRateValue = transaction?.taxName ?? taxRateTitle ?? fallbackTaxRateTitle;
const taxRateCopyValue = !canEditTaxFields ? taxRateValue : undefined;
const taxAmountTitle = formattedTaxAmount ? formattedTaxAmount.toString() : '';
const taxAmountCopyValue = !canEditTaxFields ? taxAmountTitle : undefined;
Expand Down
35 changes: 3 additions & 32 deletions src/components/TaxPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type TaxPickerProps = {
transactionID?: string;

/** Callback to fire when a tax is pressed */
onSubmit: (tax: TaxRatesOption, shouldClearTax?: boolean) => void;
onSubmit: (tax: TaxRatesOption) => void;

/** The action to take */
action?: IOUAction;
Expand Down Expand Up @@ -68,22 +68,6 @@ function TaxPicker({selectedTaxRate = '', policyID, transactionID, onSubmit, act

const shouldShowTextInput = !isTaxRatesCountBelowThreshold;

const {taxCode, taxValue} = transaction ?? {};
const hasTaxBeenDeleted = !!taxCode && taxValue !== undefined && !taxRates?.taxes?.[taxCode];
const hasTaxValueChanged = !!taxCode && taxValue !== undefined && taxRates?.taxes?.[taxCode]?.value !== taxValue;

const deletedTaxOption = !hasTaxBeenDeleted
? null
: {
code: undefined,
text: taxValue ?? '',
keyForList: taxCode ?? '',
searchText: taxValue ?? '',
tooltipText: taxValue ?? '',
isDisabled: true,
isSelected: true,
};

const selectedOptions = selectedTaxRate
? [
{
Expand All @@ -105,17 +89,11 @@ function TaxPicker({selectedTaxRate = '', policyID, transactionID, onSubmit, act
const selectedOptionKey = sections?.at(0)?.data?.find((taxRate) => taxRate.searchText === selectedTaxRate)?.keyForList;

const handleSelectRow = (newSelectedOption: TaxRatesOption) => {
if (hasTaxValueChanged) {
onSubmit(newSelectedOption, !newSelectedOption.code);
return;
}

if (selectedOptionKey === newSelectedOption.keyForList) {
onDismiss();
return;
}

onSubmit(newSelectedOption, hasTaxBeenDeleted);
onSubmit(newSelectedOption);
};

const textInputOptions = {
Expand All @@ -125,16 +103,9 @@ function TaxPicker({selectedTaxRate = '', policyID, transactionID, onSubmit, act
headerMessage: getHeaderMessageForNonUserList((sections.at(0)?.data?.length ?? 0) > 0, searchValue),
};

const updatedSections = deletedTaxOption
? sections.map((section) => ({
...section,
data: [...section.data.map((item) => (item.code === deletedTaxOption.code ? {...item, isSelected: false} : item)), deletedTaxOption],
}))
: sections;

return (
<SelectionListWithSections
sections={updatedSections}
sections={sections}
shouldShowTextInput={shouldShowTextInput}
textInputOptions={textInputOptions}
onSelectRow={handleSelectRow}
Expand Down
39 changes: 16 additions & 23 deletions src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,7 @@ function IOURequestStepTaxRatePage({
const currency = getCurrency(currentTransaction);
const decimals = getCurrencyDecimals(currency);

const updateTaxRates = (taxes: TaxRatesOption, shouldClearTax?: boolean) => {
const updateTaxRateParams = {
transactionID: currentTransaction?.transactionID,
transactionThreadReport: report,
parentReport,
taxCode: '',
taxValue: '',
taxAmount: 0,
policy,
policyTagList: policyTags,
policyCategories,
currentUserAccountIDParam,
currentUserEmailParam,
isASAPSubmitBetaEnabled,
parentReportNextStep,
};

if (shouldClearTax && isEditing) {
updateMoneyRequestTaxRate(updateTaxRateParams);
navigateBack();
return;
}
const updateTaxRates = (taxes: TaxRatesOption) => {
if (!currentTransaction || !taxes.code || !taxRates) {
Navigation.goBack();
return;
Expand All @@ -118,7 +97,21 @@ function IOURequestStepTaxRatePage({

if (isEditing) {
const newTaxCode = taxes.code;
updateMoneyRequestTaxRate({...updateTaxRateParams, taxCode: newTaxCode, taxValue, taxAmount: convertToBackendAmount(taxAmount ?? 0)});
updateMoneyRequestTaxRate({
transactionID: currentTransaction?.transactionID,
transactionThreadReport: report,
parentReport,
taxCode: newTaxCode,
taxValue,
taxAmount: convertToBackendAmount(taxAmount ?? 0),
policy,
policyTagList: policyTags,
policyCategories,
currentUserAccountIDParam,
currentUserEmailParam,
isASAPSubmitBetaEnabled,
parentReportNextStep,
});
navigateBack();
return;
}
Expand Down
Loading