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

feat: sync invoice with Xero #1606

Merged
merged 1 commit into from
Jul 15, 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
4 changes: 4 additions & 0 deletions ditto/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,10 @@
"text_667d39dc1a765800d28d0604": "Xero customer ID",
"text_667d39dc1a765800d28d0605": "Type a Xero customer ID",
"text_667d39dc1a765800d28d0607": "This customer will be created to Xero after editing in Lago",
"text_6690ef918777230093114d90": "Sync invoice to Xero",
"text_66911ce41415f40090d053ce": "Xero credit note url",
"text_66911d4b4b3c3e005c62ab49": "Sync credit note to Xero",
"text_6691221aa754dc00d250d4c0": "Xero invoice url",
"text_6543ca0fdebf76a18e159294": "Edit default currency",
"text_6543ca0fdebf76a18e159298": "This setting establishes a default currency for all object creations and for displaying the analytics page.",
"text_6543ca0fdebf76a18e15929c": "Default currency",
Expand Down
6 changes: 2 additions & 4 deletions src/components/customers/CustomerMainInfos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,7 @@ export const CustomerMainInfos = ({ loading, customer, onEdit }: CustomerMainInf
</div>
)}

{(!!customer?.netsuiteCustomer ||
integrationsLoading ||
!!connectedNetsuiteIntegration?.id) && (
{(!!customer?.netsuiteCustomer || !!connectedNetsuiteIntegration?.id) && (
<div>
<Typography variant="caption">{translate('text_66423cad72bbad009f2f568f')}</Typography>
{integrationsLoading ? (
Expand Down Expand Up @@ -440,7 +438,7 @@ export const CustomerMainInfos = ({ loading, customer, onEdit }: CustomerMainInf
</div>
)}

{(!!customer?.xeroCustomer || integrationsLoading || !!connectedXeroIntegration?.id) && (
{(!!customer?.xeroCustomer || !!connectedXeroIntegration?.id) && (
<div>
<Typography variant="caption">{translate('text_66423cad72bbad009f2f568f')}</Typography>
{integrationsLoading ? (
Expand Down
6 changes: 6 additions & 0 deletions src/core/constants/externalUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ export const buildAnrokCustomerUrl = (
export const buildXeroCustomerUrl = (xeroCustomerId?: string | null) => {
return `https://go.xero.com/app/contacts/contact/${xeroCustomerId}`
}
export const buildXeroInvoiceUrl = (xeroInvoiceId?: string | null) => {
return `https://go.xero.com/app/invoicing/view/${xeroInvoiceId}`
}
export const buildXeroCreditNoteUrl = (xeroCreditNoteId?: string | null) => {
return `https://go.xero.com/AccountsReceivable/ViewCreditNote.aspx?creditNoteID=${xeroCreditNoteId}`
}
31 changes: 22 additions & 9 deletions src/generated/graphql.tsx

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions src/layouts/CustomerInvoiceDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ gql`
integrationId
externalCustomerId
}
xeroCustomer {
id
integrationId
}
}
...InvoiceDetailsForInvoiceOverview
...InvoiceForCreditNotesTable
Expand Down Expand Up @@ -249,7 +253,9 @@ const CustomerInvoiceDetails = () => {

const { data: integrationsData } = useIntegrationsListForCustomerInvoiceDetailsQuery({
variables: { limit: 1000 },
skip: !data?.invoice?.customer?.netsuiteCustomer?.integrationId,
skip:
!data?.invoice?.customer?.netsuiteCustomer?.integrationId &&
!data?.invoice?.customer?.xeroCustomer?.integrationId,
})

const allNetsuiteIntegrations = integrationsData?.integrations?.collection.filter(
Expand Down Expand Up @@ -513,7 +519,11 @@ const CustomerInvoiceDetails = () => {
closePopper()
}}
>
{translate('text_6650b36fc702a4014c8788fd')}
{translate(
data.invoice.customer.netsuiteCustomer
? 'text_6650b36fc702a4014c8788fd'
: 'text_6690ef918777230093114d90',
)}
</Button>
)}
{status === InvoiceStatusTypeEnum.Finalized &&
Expand Down
120 changes: 78 additions & 42 deletions src/pages/CreditNoteDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '~/components/designSystem'
import { GenericPlaceholder } from '~/components/GenericPlaceholder'
import { addToast } from '~/core/apolloClient'
import { buildNetsuiteCreditNoteUrl } from '~/core/constants/externalUrls'
import { buildNetsuiteCreditNoteUrl, buildXeroCreditNoteUrl } from '~/core/constants/externalUrls'
import formatCreditNotesItems from '~/core/formats/formatCreditNotesItems'
import {
composeChargeFilterDisplayName,
Expand Down Expand Up @@ -86,6 +86,11 @@ gql`
deletedAt
applicableTimezone
netsuiteCustomer {
id
integrationId
}
xeroCustomer {
id
integrationId
}
}
Expand Down Expand Up @@ -266,7 +271,9 @@ const CreditNoteDetails = () => {
})
const { data: integrationsData } = useIntegrationsListForCreditNoteDetailsQuery({
variables: { limit: 1000 },
skip: !data?.creditNote?.customer?.netsuiteCustomer?.integrationId,
skip:
!data?.creditNote?.customer?.netsuiteCustomer?.integrationId &&
!data?.creditNote?.customer?.xeroCustomer?.integrationId,
})

const allNetsuiteIntegrations = integrationsData?.integrations?.collection.filter(
Expand Down Expand Up @@ -375,20 +382,26 @@ const CreditNoteDetails = () => {
{translate('text_637655cb50f04bf1c8379cee')}
</Button>

{!!data?.creditNote?.integrationSyncable && (
<Button
variant="quaternary"
align="left"
disabled={loadingSyncIntegrationCreditNote}
onClick={async () => {
await syncIntegrationCreditNote()

closePopper()
}}
>
{translate('text_665d742ee9853200e3a6be7f')}
</Button>
)}
{/* Note: check on xeroCustomer?.integrationId should be removed when the CN sync is fixed */}
{!!data?.creditNote?.integrationSyncable &&
!data?.creditNote?.customer?.xeroCustomer?.integrationId && (
<Button
variant="quaternary"
align="left"
disabled={loadingSyncIntegrationCreditNote}
onClick={async () => {
await syncIntegrationCreditNote()

closePopper()
}}
>
{translate(
!!data.creditNote.customer.netsuiteCustomer
? 'text_665d742ee9853200e3a6be7f'
: 'text_66911d4b4b3c3e005c62ab49',
)}
</Button>
)}
</MenuPopper>
)}
</Popper>
Expand Down Expand Up @@ -886,33 +899,56 @@ const CreditNoteDetails = () => {
)}
</TableSection>

{connectedNetsuiteIntegration && creditNote?.externalIntegrationId && (
<Stack marginTop={8} gap={6}>
<SectionHeader variant="subhead">
{translate('text_6650b36fc702a4014c878996')}
</SectionHeader>
{(connectedNetsuiteIntegration ||
data?.creditNote?.customer?.xeroCustomer?.integrationId) &&
creditNote?.externalIntegrationId && (
<Stack marginTop={8} gap={6}>
<SectionHeader variant="subhead">
{translate('text_6650b36fc702a4014c878996')}
</SectionHeader>

<div>
<InfoLine>
<Typography variant="caption" color="grey600" noWrap>
{translate('text_6684044e95fa220048a145a7')}
</Typography>
<InlineLink
target="_blank"
rel="noopener noreferrer"
to={buildNetsuiteCreditNoteUrl(
connectedNetsuiteIntegration?.accountId,
creditNote?.externalIntegrationId,
)}
>
<Typography variant="body" color="info600">
{creditNote?.externalIntegrationId} <Icon name="outside" />
</Typography>
</InlineLink>
</InfoLine>
</div>
</Stack>
)}
{!!connectedNetsuiteIntegration && (
<div>
<InfoLine>
<Typography variant="caption" color="grey600" noWrap>
{translate('text_6684044e95fa220048a145a7')}
</Typography>
<InlineLink
target="_blank"
rel="noopener noreferrer"
to={buildNetsuiteCreditNoteUrl(
connectedNetsuiteIntegration?.accountId,
creditNote?.externalIntegrationId,
)}
>
<Typography variant="body" color="info600">
{creditNote?.externalIntegrationId} <Icon name="outside" />
</Typography>
</InlineLink>
</InfoLine>
</div>
)}

{!!data?.creditNote?.customer?.xeroCustomer?.integrationId && (
<div>
<InfoLine>
<Typography variant="caption" color="grey600" noWrap>
{translate('text_66911ce41415f40090d053ce')}
</Typography>
<InlineLink
target="_blank"
rel="noopener noreferrer"
to={buildXeroCreditNoteUrl(creditNote?.externalIntegrationId)}
>
<Typography variant="body" color="info600">
{creditNote?.externalIntegrationId} <Icon name="outside" />
</Typography>
</InlineLink>
</InfoLine>
</div>
)}
</Stack>
)}
</>
</Content>
)}
Expand Down
80 changes: 53 additions & 27 deletions src/pages/InvoiceOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { InvoiceCreditNotesTable } from '~/components/invoices/InvoiceCreditNotesTable'
import { InvoiceCustomerInfos } from '~/components/invoices/InvoiceCustomerInfos'
import { Metadatas } from '~/components/invoices/Metadatas'
import { buildNetsuiteInvoiceUrl } from '~/core/constants/externalUrls'
import { buildNetsuiteInvoiceUrl, buildXeroInvoiceUrl } from '~/core/constants/externalUrls'
import formatCreditNotesItems from '~/core/formats/formatCreditNotesItems'
import { formatDateToTZ } from '~/core/timezone'
import {
Expand Down Expand Up @@ -51,6 +51,9 @@ gql`
netsuiteCustomer {
externalCustomerId
}
xeroCustomer {
externalCustomerId
}
}
}

Expand Down Expand Up @@ -239,33 +242,56 @@ const InvoiceOverview = memo(
/>
)}

{connectedNetsuiteIntegration && invoice?.externalIntegrationId && (
<Stack marginTop={8} gap={6}>
<SectionHeader variant="subhead">
{translate('text_6650b36fc702a4014c878996')}
</SectionHeader>
{(connectedNetsuiteIntegration ||
invoice.customer.xeroCustomer?.externalCustomerId) &&
invoice?.externalIntegrationId && (
<Stack marginTop={8} gap={6}>
<SectionHeader variant="subhead">
{translate('text_6650b36fc702a4014c878996')}
</SectionHeader>

<div>
<InfoLine>
<Typography variant="caption" color="grey600" noWrap>
{translate('text_6650b36fc702a4014c87899a')}
</Typography>
<InlineLink
target="_blank"
rel="noopener noreferrer"
to={buildNetsuiteInvoiceUrl(
connectedNetsuiteIntegration?.accountId,
invoice?.externalIntegrationId,
)}
>
<Typography variant="body" color="info600">
{invoice?.externalIntegrationId} <Icon name="outside" />
</Typography>
</InlineLink>
</InfoLine>
</div>
</Stack>
)}
{!!connectedNetsuiteIntegration && (
<div>
<InfoLine>
<Typography variant="caption" color="grey600" noWrap>
{translate('text_6650b36fc702a4014c87899a')}
</Typography>
<InlineLink
target="_blank"
rel="noopener noreferrer"
to={buildNetsuiteInvoiceUrl(
connectedNetsuiteIntegration?.accountId,
invoice?.externalIntegrationId,
)}
>
<Typography variant="body" color="info600">
{invoice?.externalIntegrationId} <Icon name="outside" />
</Typography>
</InlineLink>
</InfoLine>
</div>
)}

{!!invoice.customer.xeroCustomer?.externalCustomerId && (
<div>
<InfoLine>
<Typography variant="caption" color="grey600" noWrap>
{translate('text_6691221aa754dc00d250d4c0')}
</Typography>
<InlineLink
target="_blank"
rel="noopener noreferrer"
to={buildXeroInvoiceUrl(invoice?.externalIntegrationId)}
>
<Typography variant="body" color="info600">
{invoice?.externalIntegrationId} <Icon name="outside" />
</Typography>
</InlineLink>
</InfoLine>
</div>
)}
</Stack>
)}

{invoice?.status !== InvoiceStatusTypeEnum.Draft && (
<Metadatas customer={customer} invoice={invoice} />
Expand Down
Loading