Skip to content

Commit

Permalink
feat: handle invoice tax status pending (#1937)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansmonjol authored Dec 30, 2024
1 parent e036d1d commit add9fce
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 44 deletions.
27 changes: 21 additions & 6 deletions src/components/customers/CustomerInvoicesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
InvoiceForUpdateInvoicePaymentStatusFragmentDoc,
InvoicePaymentStatusTypeEnum,
InvoiceStatusTypeEnum,
InvoiceTaxStatusTypeEnum,
LagoApiError,
TimezoneEnum,
useDownloadInvoiceItemMutation,
Expand All @@ -38,6 +39,7 @@ gql`
fragment InvoiceListItem on Invoice {
id
status
taxStatus
paymentStatus
paymentOverdue
number
Expand Down Expand Up @@ -208,7 +210,7 @@ export const CustomerInvoicesList: FC<CustomerInvoicesListProps> = ({
key: 'number',
minWidth: 160,
title: translate('text_63ac86d797f728a87b2f9fad'),
content: (invoice) => invoice.number,
content: (invoice) => invoice.number || '-',
},
{
key: 'totalAmountCents',
Expand All @@ -217,7 +219,11 @@ export const CustomerInvoicesList: FC<CustomerInvoicesListProps> = ({
minWidth: 160,
title: translate('text_63ac86d797f728a87b2f9fb9'),
content: (invoice) => {
if (invoice.status === InvoiceStatusTypeEnum.Failed) return '-'
if (
invoice.status === InvoiceStatusTypeEnum.Failed ||
invoice.taxStatus === InvoiceTaxStatusTypeEnum.Pending
)
return '-'

const currency = invoice.currency || CurrencyEnum.Usd
const amount = deserializeAmount(invoice.totalAmountCents, currency)
Expand Down Expand Up @@ -295,13 +301,19 @@ export const CustomerInvoicesList: FC<CustomerInvoicesListProps> = ({
},
]}
actionColumn={(invoice) => {
const { status, paymentStatus, voidable } = invoice
const { status, paymentStatus, voidable, taxStatus } = invoice

const canDownload =
![InvoiceStatusTypeEnum.Draft, InvoiceStatusTypeEnum.Failed].includes(status) &&
![
InvoiceStatusTypeEnum.Draft,
InvoiceStatusTypeEnum.Failed,
InvoiceStatusTypeEnum.Pending,
].includes(status) &&
taxStatus !== InvoiceTaxStatusTypeEnum.Pending &&
hasPermissions(['invoicesView'])
const canFinalize =
![InvoiceStatusTypeEnum.Failed].includes(status) && hasPermissions(['invoicesUpdate'])
![InvoiceStatusTypeEnum.Failed, InvoiceStatusTypeEnum.Pending].includes(status) &&
hasPermissions(['invoicesUpdate'])
const canRetryCollect =
status === InvoiceStatusTypeEnum.Finalized &&
[InvoicePaymentStatusTypeEnum.Failed, InvoicePaymentStatusTypeEnum.Pending].includes(
Expand All @@ -313,7 +325,10 @@ export const CustomerInvoicesList: FC<CustomerInvoicesListProps> = ({
InvoiceStatusTypeEnum.Draft,
InvoiceStatusTypeEnum.Voided,
InvoiceStatusTypeEnum.Failed,
].includes(status) && hasPermissions(['invoicesUpdate'])
InvoiceStatusTypeEnum.Pending,
].includes(status) &&
taxStatus !== InvoiceTaxStatusTypeEnum.Pending &&
hasPermissions(['invoicesUpdate'])
const canVoid =
status === InvoiceStatusTypeEnum.Finalized &&
[InvoicePaymentStatusTypeEnum.Pending, InvoicePaymentStatusTypeEnum.Failed].includes(
Expand Down
1 change: 1 addition & 0 deletions src/components/customers/CustomerInvoicesTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const CustomerInvoicesTab = ({ customerId, customerTimezone }: CustomerIn
InvoiceStatusTypeEnum.Finalized,
InvoiceStatusTypeEnum.Voided,
InvoiceStatusTypeEnum.Failed,
InvoiceStatusTypeEnum.Pending,
],
},
notifyOnNetworkStatusChange: true,
Expand Down
16 changes: 11 additions & 5 deletions src/components/invoices/InvoicesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,13 @@ const InvoicesList = ({
const { status, paymentStatus, voidable } = invoice

const canDownload =
![InvoiceStatusTypeEnum.Draft, InvoiceStatusTypeEnum.Failed].includes(status) &&
hasPermissions(['invoicesView'])
![
InvoiceStatusTypeEnum.Draft,
InvoiceStatusTypeEnum.Failed,
InvoiceStatusTypeEnum.Pending,
].includes(status) && hasPermissions(['invoicesView'])
const canFinalize =
![InvoiceStatusTypeEnum.Failed].includes(status) &&
![InvoiceStatusTypeEnum.Failed, InvoiceStatusTypeEnum.Pending].includes(status) &&
hasPermissions(['invoicesUpdate'])
const canRetryCollect =
status === InvoiceStatusTypeEnum.Finalized &&
Expand All @@ -163,6 +166,7 @@ const InvoicesList = ({
InvoiceStatusTypeEnum.Draft,
InvoiceStatusTypeEnum.Voided,
InvoiceStatusTypeEnum.Failed,
InvoiceStatusTypeEnum.Pending,
].includes(status) && hasPermissions(['invoicesUpdate'])
const canVoid =
status === InvoiceStatusTypeEnum.Finalized &&
Expand Down Expand Up @@ -278,7 +282,7 @@ const InvoicesList = ({
minWidth: 160,
content: ({ number }) => (
<Typography variant="body" noWrap>
{number}
{number || '-'}
</Typography>
),
},
Expand All @@ -290,7 +294,9 @@ const InvoicesList = ({
content: ({ totalAmountCents, currency, status }) => {
return (
<Typography variant="bodyHl" color="textSecondary" noWrap>
{status === InvoiceStatusTypeEnum.Failed
{[InvoiceStatusTypeEnum.Failed, InvoiceStatusTypeEnum.Pending].includes(
status,
)
? '-'
: intlFormatNumber(
deserializeAmount(totalAmountCents, currency || CurrencyEnum.Usd),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
CurrencyEnum,
InvoiceForDetailsTableFooterFragment,
InvoiceStatusTypeEnum,
InvoiceTaxStatusTypeEnum,
InvoiceTypeEnum,
} from '~/generated/graphql'
import { useInternationalization } from '~/hooks/core/useInternationalization'
Expand All @@ -24,6 +25,7 @@ gql`
currency
invoiceType
status
taxStatus
prepaidCreditAmountCents
progressiveBillingCreditAmountCents
versionNumber
Expand Down Expand Up @@ -354,7 +356,7 @@ export const InvoiceDetailsTableFooter = memo(
<Alert type="info">{translate('text_63b6f4e9b074e3b8beebb97f')}</Alert>
</NoShadowTD>
</tr>
) : hasTaxProviderError ? (
) : hasTaxProviderError || invoice.taxStatus === InvoiceTaxStatusTypeEnum.Pending ? (
<tr>
<td></td>
<NoShadowTD colSpan={4}>
Expand Down
2 changes: 2 additions & 0 deletions src/core/constants/statusInvoiceMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const invoiceStatusMapping = ({
return { label: 'finalized', type: StatusType.success }
case InvoiceStatusTypeEnum.Voided:
return { label: 'voided', type: StatusType.disabled }
case InvoiceStatusTypeEnum.Pending:
return { label: 'pending', type: StatusType.default }
default:
return { label: 'n/a', type: StatusType.default }
}
Expand Down
43 changes: 27 additions & 16 deletions src/generated/graphql.tsx

Large diffs are not rendered by default.

47 changes: 38 additions & 9 deletions src/layouts/CustomerInvoiceDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
InvoiceMetadatasForMetadataDrawerFragmentDoc,
InvoicePaymentStatusTypeEnum,
InvoiceStatusTypeEnum,
InvoiceTaxStatusTypeEnum,
InvoiceTypeEnum,
LagoApiError,
NetsuiteIntegration,
Expand Down Expand Up @@ -98,6 +99,7 @@ gql`
number
paymentStatus
status
taxStatus
totalAmountCents
currency
refundableAmountCents
Expand Down Expand Up @@ -467,6 +469,7 @@ const CustomerInvoiceDetails = () => {
totalAmountCents,
currency,
status,
taxStatus,
creditableAmountCents,
refundableAmountCents,
voidable,
Expand Down Expand Up @@ -552,7 +555,14 @@ const CustomerInvoiceDetails = () => {
},
]

if (![InvoiceStatusTypeEnum.Draft, InvoiceStatusTypeEnum.Failed].includes(status)) {
if (
![
InvoiceStatusTypeEnum.Draft,
InvoiceStatusTypeEnum.Failed,
InvoiceStatusTypeEnum.Pending,
].includes(status) &&
taxStatus !== InvoiceTaxStatusTypeEnum.Pending
) {
tabs.push({
title: translate('text_636bdef6565341dcb9cfb125'),
link: generatePath(CUSTOMER_INVOICE_DETAILS_ROUTE, {
Expand Down Expand Up @@ -593,10 +603,11 @@ const CustomerInvoiceDetails = () => {
connectedSalesforceIntegration,
goToPreviousRoute,
syncHubspotIntegrationInvoice,
loadingSyncHubspotIntegrationInvoice,
syncSalesforceIntegrationInvoice,
loadingSyncHubspotIntegrationInvoice,
loadingSyncSalesforceIntegrationInvoice,
status,
taxStatus,
])

return (
Expand Down Expand Up @@ -636,6 +647,7 @@ const CustomerInvoiceDetails = () => {
{translate('text_1724164767403kyknbaw13mg')}
</Button>
) : status === InvoiceStatusTypeEnum.Draft &&
taxStatus !== InvoiceTaxStatusTypeEnum.Pending &&
hasPermissions(['draftInvoicesUpdate']) ? (
<>
<Button
Expand All @@ -662,7 +674,8 @@ const CustomerInvoiceDetails = () => {
{translate('text_63a41a8eabb9ae67047c1c06')}
</Button>
</>
) : (
) : status !== InvoiceStatusTypeEnum.Pending ||
taxStatus !== InvoiceTaxStatusTypeEnum.Pending ? (
<>
<Button
variant="quaternary"
Expand Down Expand Up @@ -729,7 +742,7 @@ const CustomerInvoiceDetails = () => {
</>
)}
</>
)}
) : null}
<Button
variant="quaternary"
align="left"
Expand All @@ -745,9 +758,13 @@ const CustomerInvoiceDetails = () => {
>
{translate('text_634687079be251fdb438339b')}
</Button>
{status !== InvoiceStatusTypeEnum.Draft &&
status !== InvoiceStatusTypeEnum.Voided &&
status !== InvoiceStatusTypeEnum.Failed &&
{![
InvoiceStatusTypeEnum.Draft,
InvoiceStatusTypeEnum.Voided,
InvoiceStatusTypeEnum.Failed,
InvoiceStatusTypeEnum.Pending,
].includes(status) &&
taxStatus !== InvoiceTaxStatusTypeEnum.Pending &&
hasPermissions(['invoicesUpdate']) && (
<>
<Button
Expand Down Expand Up @@ -869,7 +886,7 @@ const CustomerInvoiceDetails = () => {
</Popper>
)}
</PageHeader>
{!!errorMessage && (
{!!errorMessage ? (
<Alert fullWidth className="md:px-12" type="warning">
<Stack>
<Typography variant="body" color="grey700">
Expand All @@ -879,7 +896,19 @@ const CustomerInvoiceDetails = () => {
<Typography variant="caption">{translate(errorMessage)}</Typography>
</Stack>
</Alert>
)}
) : taxStatus === InvoiceTaxStatusTypeEnum.Pending ? (
<Alert fullWidth className="md:px-12" type="info">
<div className="flex flex-col">
<Typography variant="body" color="grey700">
{translate('text_1735045451930tezr0et3e6l')}
</Typography>

<Typography variant="caption" color="grey600">
{translate('text_1735045451931zfgc6yvvcfm')}
</Typography>
</div>
</Alert>
) : null}
{hasError ? (
<GenericPlaceholder
title={translate('text_634812d6f16b31ce5cbf4111')}
Expand Down
12 changes: 8 additions & 4 deletions src/pages/InvoiceOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
HubspotIntegrationInfosForInvoiceOverviewFragment,
Invoice,
InvoiceStatusTypeEnum,
InvoiceTaxStatusTypeEnum,
NetsuiteIntegrationInfosForInvoiceOverviewFragment,
RefreshInvoiceMutationFn,
RetryInvoiceMutationFn,
Expand All @@ -57,6 +58,7 @@ gql`
id
invoiceType
status
taxStatus
issuingDate
externalIntegrationId
taxProviderVoidable
Expand Down Expand Up @@ -219,6 +221,8 @@ const InvoiceOverview = memo(
showHubspotSection ||
showSalesforceSection

const isTaxStatusPending = invoice?.taxStatus === InvoiceTaxStatusTypeEnum.Pending

return (
<>
<SectionHeader variant="subhead">
Expand All @@ -229,7 +233,7 @@ const InvoiceOverview = memo(
<Button
variant="quaternary"
startIcon="reload"
disabled={loading || loadingRefreshInvoice}
disabled={loading || loadingRefreshInvoice || isTaxStatusPending}
onClick={async () => {
await refreshInvoice()
}}
Expand All @@ -238,7 +242,7 @@ const InvoiceOverview = memo(
</Button>
<Button
variant="quaternary"
disabled={loading}
disabled={loading || isTaxStatusPending}
onClick={() => {
finalizeInvoiceRef.current?.openDialog(invoice, goToPreviousRoute)
}}
Expand All @@ -249,7 +253,7 @@ const InvoiceOverview = memo(
) : hasTaxProviderError ? (
<Button
variant="quaternary"
disabled={loading || loadingRetryInvoice}
disabled={loading || loadingRetryInvoice || isTaxStatusPending}
onClick={async () => {
await retryInvoice()
}}
Expand All @@ -261,7 +265,7 @@ const InvoiceOverview = memo(
!loading && (
<Button
variant="quaternary"
disabled={loadingInvoiceDownload}
disabled={loadingInvoiceDownload || isTaxStatusPending}
onClick={async () => {
await downloadInvoice({
variables: { input: { id: invoiceId || '' } },
Expand Down
8 changes: 5 additions & 3 deletions translations/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@
"text_63ac86d797f728a87b2f9fb9": "Amount",
"text_63ac86d797f728a87b2f9fbf": "Issuing date",
"text_63b5d225b075850e0fe489f4": "Payment",
"text_63ac86d897f728a87b2fa031": "Copy invoice_id",
"text_63ac86d897f728a87b2fa031": "Copy invoice id",
"text_63ac86d897f728a87b2fa0b0": "Invoice ID copied to clipboard",
"text_63ac86d897f728a87b2fa039": "Resend for collection",
"text_63ac86d897f728a87b2fa0b3": "Invoice successfully re-sent for collection",
Expand Down Expand Up @@ -1434,7 +1434,7 @@
"text_63b6f4e9b074e3b8beebb97f": "Coupons, prepaid credits and credit notes will impact the invoice once it’s finalized.",
"text_634687079be251fdb438338f": "Actions",
"text_634687079be251fdb4383395": "Download invoice",
"text_634687079be251fdb438339b": "Copy invoice_id",
"text_634687079be251fdb438339b": "Copy invoice id",
"text_634687079be251fdb43833ad": "for {{totalAmount}}",
"text_634687079be251fdb43833b7": "Overview",
"text_634687079be251fdb43833b9": "Download invoice",
Expand Down Expand Up @@ -2753,5 +2753,7 @@
"text_17338418252493b2rz0ks49m": "Invoice custom section successfully created",
"text_1733841825249i5g7vr4gnzo": "Invoice custom section successfully edited",
"text_17326350108761jc0z8eusa8": "Invoice preview",
"text_173255335844629sa49oljif": "Preview invoice"
"text_173255335844629sa49oljif": "Preview invoice",
"text_1735045451930tezr0et3e6l": "Invoice is pending finalization.",
"text_1735045451931zfgc6yvvcfm": "This invoice is in the queue, waiting to be finalized. It may take a bit of time. Please refresh or check back later."
}

0 comments on commit add9fce

Please sign in to comment.