@@ -98,8 +98,6 @@ import InvoiceOverview from '~/pages/InvoiceOverview'
98
98
import ErrorImage from '~/public/images/maneki/error.svg'
99
99
import { MenuPopper , PageHeader , theme } from '~/styles'
100
100
101
- import { useOrganizationInfos } from '../hooks/useOrganizationInfos'
102
-
103
101
gql `
104
102
fragment AllInvoiceDetailsForCustomerInvoiceDetails on Invoice {
105
103
id
@@ -282,13 +280,13 @@ const CustomerInvoiceDetails = () => {
282
280
const { goBack } = useLocationHistory ( )
283
281
const { isPremium } = useCurrentUser ( )
284
282
const { hasPermissions } = usePermissions ( )
285
- const { organization : { premiumIntegrations } = { } } = useOrganizationInfos ( )
286
283
const finalizeInvoiceRef = useRef < FinalizeInvoiceDialogRef > ( null )
287
284
const premiumWarningDialogRef = useRef < PremiumWarningDialogRef > ( null )
288
285
const updateInvoicePaymentStatusDialog = useRef < UpdateInvoicePaymentStatusDialogRef > ( null )
289
286
const addMetadataDrawerDialogRef = useRef < AddMetadataDrawerRef > ( null )
290
287
const voidInvoiceDialogRef = useRef < VoidInvoiceDialogRef > ( null )
291
288
const disputeInvoiceDialogRef = useRef < DisputeInvoiceDialogRef > ( null )
289
+
292
290
const [ refreshInvoice , { loading : loadingRefreshInvoice } ] = useRefreshInvoiceMutation ( {
293
291
variables : { input : { id : invoiceId || '' } } ,
294
292
context : {
@@ -437,6 +435,7 @@ const CustomerInvoiceDetails = () => {
437
435
number,
438
436
paymentStatus,
439
437
totalAmountCents,
438
+ totalPaidAmountCents,
440
439
totalDueAmountCents,
441
440
currency,
442
441
status,
@@ -449,6 +448,11 @@ const CustomerInvoiceDetails = () => {
449
448
associatedActiveWalletPresent,
450
449
} = ( data ?. invoice as AllInvoiceDetailsForCustomerInvoiceDetailsFragment ) || { }
451
450
451
+ const canRecordPayment =
452
+ Number ( totalDueAmountCents ) > 0 &&
453
+ hasPermissions ( [ 'paymentsCreate' ] ) &&
454
+ Number ( totalPaidAmountCents ) < Number ( totalAmountCents )
455
+
452
456
const hasError = ( ! ! error || ! data ?. invoice ) && ! loading
453
457
const hasTaxProviderError = errorDetails ?. find (
454
458
( { errorCode } ) => errorCode === ErrorCodesEnum . TaxError ,
@@ -732,7 +736,7 @@ const CustomerInvoiceDetails = () => {
732
736
) }
733
737
</ >
734
738
) : null }
735
- { totalDueAmountCents > 0 && hasPermissions ( [ 'paymentsCreate' ] ) && (
739
+ { canRecordPayment && (
736
740
< Button
737
741
variant = "quaternary"
738
742
align = "left"
0 commit comments