Skip to content

Commit 1c35369

Browse files
committed
fix: record payment condition
1 parent d0ee5af commit 1c35369

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/components/customers/CustomerInvoicesList.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ export const CustomerInvoicesList: FC<CustomerInvoicesListProps> = ({
331331
taxStatus,
332332
totalPaidAmountCents,
333333
totalDueAmountCents,
334+
totalAmountCents,
334335
} = invoice
335336

336337
const { disabledIssueCreditNoteButton, disabledIssueCreditNoteButtonLabel } =
@@ -378,9 +379,9 @@ export const CustomerInvoicesList: FC<CustomerInvoicesListProps> = ({
378379
![InvoiceStatusTypeEnum.Draft, InvoiceStatusTypeEnum.Voided].includes(status) &&
379380
hasPermissions(['creditNotesCreate'])
380381
const canRecordPayment =
381-
totalDueAmountCents > 0 &&
382+
Number(totalDueAmountCents) > 0 &&
382383
hasPermissions(['paymentsCreate']) &&
383-
totalPaidAmountCents < totalDueAmountCents
384+
Number(totalPaidAmountCents) < Number(totalAmountCents)
384385

385386
return [
386387
canDownload

src/components/invoices/InvoicesList.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,14 @@ const InvoicesList = ({
165165
isLoading={isLoading}
166166
hasError={!!error}
167167
actionColumn={(invoice) => {
168-
const { status, paymentStatus, voidable, totalDueAmountCents } = invoice
168+
const {
169+
status,
170+
paymentStatus,
171+
voidable,
172+
totalDueAmountCents,
173+
totalPaidAmountCents,
174+
totalAmountCents,
175+
} = invoice
169176

170177
const { disabledIssueCreditNoteButton, disabledIssueCreditNoteButtonLabel } =
171178
createCreditNoteForInvoiceButtonProps({
@@ -209,7 +216,10 @@ const InvoicesList = ({
209216
const canIssueCreditNote =
210217
![InvoiceStatusTypeEnum.Draft, InvoiceStatusTypeEnum.Voided].includes(status) &&
211218
hasPermissions(['creditNotesCreate'])
212-
const canRecordPayment = totalDueAmountCents > 0 && hasPermissions(['paymentsCreate'])
219+
const canRecordPayment =
220+
Number(totalDueAmountCents) > 0 &&
221+
hasPermissions(['paymentsCreate']) &&
222+
Number(totalPaidAmountCents) < Number(totalAmountCents)
213223

214224
return [
215225
canDownload

src/pages/CustomerInvoiceDetails.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ import InvoiceOverview from '~/pages/InvoiceOverview'
9898
import ErrorImage from '~/public/images/maneki/error.svg'
9999
import { MenuPopper, PageHeader, theme } from '~/styles'
100100

101-
import { useOrganizationInfos } from '../hooks/useOrganizationInfos'
102-
103101
gql`
104102
fragment AllInvoiceDetailsForCustomerInvoiceDetails on Invoice {
105103
id
@@ -282,13 +280,13 @@ const CustomerInvoiceDetails = () => {
282280
const { goBack } = useLocationHistory()
283281
const { isPremium } = useCurrentUser()
284282
const { hasPermissions } = usePermissions()
285-
const { organization: { premiumIntegrations } = {} } = useOrganizationInfos()
286283
const finalizeInvoiceRef = useRef<FinalizeInvoiceDialogRef>(null)
287284
const premiumWarningDialogRef = useRef<PremiumWarningDialogRef>(null)
288285
const updateInvoicePaymentStatusDialog = useRef<UpdateInvoicePaymentStatusDialogRef>(null)
289286
const addMetadataDrawerDialogRef = useRef<AddMetadataDrawerRef>(null)
290287
const voidInvoiceDialogRef = useRef<VoidInvoiceDialogRef>(null)
291288
const disputeInvoiceDialogRef = useRef<DisputeInvoiceDialogRef>(null)
289+
292290
const [refreshInvoice, { loading: loadingRefreshInvoice }] = useRefreshInvoiceMutation({
293291
variables: { input: { id: invoiceId || '' } },
294292
context: {
@@ -437,6 +435,7 @@ const CustomerInvoiceDetails = () => {
437435
number,
438436
paymentStatus,
439437
totalAmountCents,
438+
totalPaidAmountCents,
440439
totalDueAmountCents,
441440
currency,
442441
status,
@@ -449,6 +448,11 @@ const CustomerInvoiceDetails = () => {
449448
associatedActiveWalletPresent,
450449
} = (data?.invoice as AllInvoiceDetailsForCustomerInvoiceDetailsFragment) || {}
451450

451+
const canRecordPayment =
452+
Number(totalDueAmountCents) > 0 &&
453+
hasPermissions(['paymentsCreate']) &&
454+
Number(totalPaidAmountCents) < Number(totalAmountCents)
455+
452456
const hasError = (!!error || !data?.invoice) && !loading
453457
const hasTaxProviderError = errorDetails?.find(
454458
({ errorCode }) => errorCode === ErrorCodesEnum.TaxError,
@@ -732,7 +736,7 @@ const CustomerInvoiceDetails = () => {
732736
)}
733737
</>
734738
) : null}
735-
{totalDueAmountCents > 0 && hasPermissions(['paymentsCreate']) && (
739+
{canRecordPayment && (
736740
<Button
737741
variant="quaternary"
738742
align="left"

0 commit comments

Comments
 (0)