Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: show details for all percentage fees #1771

Merged
merged 1 commit into from
Oct 3, 2024
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
42 changes: 28 additions & 14 deletions src/components/invoices/details/InvoiceDetailsTableBodyLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ export const calculateIfDetailsShouldBeDisplayed = (
fee?.charge?.chargeModel === ChargeModelEnum.Volume && !!fee?.amountDetails?.flatUnitAmount
const isValidAdvanceRecurringPackage =
fee?.charge?.chargeModel === ChargeModelEnum.Package && !!fee?.amountDetails?.freeUnits
const isValidAdvanceRecurringPercentage =
fee?.charge?.chargeModel === ChargeModelEnum.Percentage &&
!!fee?.amountDetails?.fixedFeeUnitAmount
const isValidAdvanceGraduated =
fee?.charge?.chargeModel === ChargeModelEnum.Graduated &&
!!fee?.amountDetails?.graduatedRanges?.[0].toValue
Expand All @@ -134,16 +131,23 @@ export const calculateIfDetailsShouldBeDisplayed = (
!!fee?.charge?.billableMetric?.recurring &&
(isValidAdvanceRecurringVolume ||
isValidAdvanceRecurringPackage ||
isValidAdvanceRecurringPercentage ||
isValidAdvanceGraduated ||
isValidAdvanceGraduatedPercentage)

// Always show details for percentage charge if it has fixedFeeUnitAmount
const isPercentageWithDetailsAndNotOnlyRate =
fee?.charge?.chargeModel === ChargeModelEnum.Percentage &&
(!!Number(fee?.amountDetails?.fixedFeeUnitAmount) ||
!!Number(fee?.amountDetails?.freeUnits) ||
!!Number(fee?.amountDetails?.freeEvents) ||
!!Number(fee?.amountDetails?.minMaxAdjustmentTotalAmount))

const shouldDisplayFeeDetail =
!!fee &&
!isTrueUpFee &&
fee.adjustedFeeType !== AdjustedFeeTypeEnum.AdjustedAmount &&
!fee?.metadata?.isSubscriptionFee &&
(isInArrears || isAdvanceRecurring) &&
(isInArrears || isAdvanceRecurring || isPercentageWithDetailsAndNotOnlyRate) &&
fee?.charge?.chargeModel !== ChargeModelEnum.Standard &&
fee.feeType !== FeeTypesEnum.AddOn &&
fee.feeType !== FeeTypesEnum.Credit &&
Expand Down Expand Up @@ -229,15 +233,25 @@ export const InvoiceDetailsTableBodyLine = memo(
</Typography>
</td>
{canHaveUnitPrice && (
<td>
<Typography variant="body" color="grey700">
{intlFormatNumber(fee?.preciseUnitAmount || 0, {
currencyDisplay: 'symbol',
currency,
maximumFractionDigits: 15,
})}
</Typography>
</td>
<>
{chargeModel === ChargeModelEnum.Percentage ? (
<td>
<Typography variant="body" color="grey700">
{fee?.amountDetails?.rate}%
</Typography>
</td>
) : (
<td>
<Typography variant="body" color="grey700">
{intlFormatNumber(fee?.preciseUnitAmount || 0, {
currencyDisplay: 'symbol',
currency,
maximumFractionDigits: 15,
})}
</Typography>
</td>
)}
</>
)}
{!hideVat && (
<td>
Expand Down
Loading
Loading