-
-
Notifications
You must be signed in to change notification settings - Fork 344
feat: defer invoices below 5 EUR with carry-over #3525
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
Draft
dkrizan
wants to merge
10
commits into
main
Choose a base branch
from
dkrizan/invoice-carry-over
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+996
−57
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
597e67a
feat: add carry-over history admin UI in administration invoices view
dkrizan 5dd2ce6
feat: show carry-over threshold notice in usage details dialog
dkrizan d3ebb02
chore: eslint
dkrizan 4d3db31
refactor: read minUsageInvoiceAmount from init-data instead of UsageM…
dkrizan 969342b
feat: show deferred carry-over amounts in invoice Usage details dialog
dkrizan 203893f
chore: billingApiSchema.generated.ts updated
dkrizan 6ac4834
fix: pass organizationId as a prop to AdminInvoiceUsage component to …
dkrizan 47e1905
feat: localize labels in CarryOversSection and adjust navigation link…
dkrizan fda3db8
refactor: extract invoice PDF download logic to reusable hook and com…
dkrizan dc49f17
style: adjust left padding in OrgInvoicesSection box component
dkrizan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
backend/data/src/main/kotlin/io/tolgee/dtos/response/PublicBillingConfigurationDTO.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| package io.tolgee.dtos.response | ||
|
|
||
| import java.math.BigDecimal | ||
|
|
||
| class PublicBillingConfigurationDTO( | ||
| val enabled: Boolean, | ||
| val minUsageInvoiceAmount: BigDecimal? = null, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,68 +1,37 @@ | ||
| import { FC } from 'react'; | ||
|
|
||
| import { useOrganization } from 'tg.views/organizations/useOrganization'; | ||
| import LoadingButton from 'tg.component/common/form/LoadingButton'; | ||
| import { components } from 'tg.service/billingApiSchema.generated'; | ||
| import { useConfig } from 'tg.globalContext/helpers'; | ||
| import { useBillingApiMutation } from 'tg.service/http/useQueryApi'; | ||
| import { useInvoicePdfDownload } from './useInvoicePdfDownload'; | ||
| import { PdfDownloadButton } from './PdfDownloadButton'; | ||
|
|
||
| type DownloadButtonProps = { | ||
| invoice: components['schemas']['InvoiceModel']; | ||
| }; | ||
|
|
||
| export const DownloadButton: FC<DownloadButtonProps> = (props) => { | ||
| export const DownloadButton: FC<DownloadButtonProps> = ({ invoice }) => { | ||
| const organization = useOrganization(); | ||
| const config = useConfig(); | ||
| const { onSuccess } = useInvoicePdfDownload(invoice); | ||
|
|
||
| const pdfMutation = useBillingApiMutation({ | ||
| url: '/v2/organizations/{organizationId}/billing/invoices/{invoiceId}/pdf', | ||
| method: 'get', | ||
| fetchOptions: { | ||
| rawResponse: true, | ||
| }, | ||
| fetchOptions: { rawResponse: true }, | ||
| }); | ||
|
|
||
| const onDownload = () => { | ||
| pdfMutation.mutate( | ||
| { | ||
| path: { | ||
| organizationId: organization!.id, | ||
| invoiceId: props.invoice.id, | ||
| }, | ||
| }, | ||
| { | ||
| async onSuccess(response) { | ||
| const res = response as unknown as Response; | ||
| const data = await res.blob(); | ||
| const url = URL.createObjectURL(data as any as Blob); | ||
| try { | ||
| const a = document.createElement('a'); | ||
| try { | ||
| a.href = url; | ||
| a.download = `${config.appName.toLowerCase()}-${ | ||
| props.invoice.number | ||
| }.pdf`; | ||
|
|
||
| a.click(); | ||
| } finally { | ||
| a.remove(); | ||
| } | ||
| } finally { | ||
| setTimeout(() => URL.revokeObjectURL(url), 7000); | ||
| } | ||
| }, | ||
| } | ||
| { path: { organizationId: organization!.id, invoiceId: invoice.id } }, | ||
| { onSuccess } | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <LoadingButton | ||
| disabled={!props.invoice.pdfReady} | ||
| loading={pdfMutation.isLoading} | ||
| onClick={onDownload} | ||
| size="small" | ||
| > | ||
| </LoadingButton> | ||
| <PdfDownloadButton | ||
| invoice={invoice} | ||
| onDownload={onDownload} | ||
| isLoading={pdfMutation.isLoading} | ||
| /> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { FC } from 'react'; | ||
|
|
||
| import LoadingButton from 'tg.component/common/form/LoadingButton'; | ||
| import { components } from 'tg.service/billingApiSchema.generated'; | ||
|
|
||
| type PdfDownloadButtonProps = { | ||
| invoice: components['schemas']['InvoiceModel']; | ||
| onDownload: () => void; | ||
| isLoading: boolean; | ||
| }; | ||
|
|
||
| export const PdfDownloadButton: FC<PdfDownloadButtonProps> = ({ | ||
| invoice, | ||
| onDownload, | ||
| isLoading, | ||
| }) => { | ||
| return ( | ||
| <LoadingButton | ||
| disabled={!invoice.pdfReady} | ||
| loading={isLoading} | ||
| onClick={onDownload} | ||
| size="small" | ||
| > | ||
| </LoadingButton> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { useConfig } from 'tg.globalContext/helpers'; | ||
| import { components } from 'tg.service/billingApiSchema.generated'; | ||
|
|
||
| type InvoiceModel = components['schemas']['InvoiceModel']; | ||
|
|
||
| export function useInvoicePdfDownload(invoice: InvoiceModel) { | ||
| const config = useConfig(); | ||
|
|
||
| const onSuccess = async (response: unknown) => { | ||
| const res = response as Response; | ||
| const data = await res.blob(); | ||
| const url = URL.createObjectURL(data); | ||
| try { | ||
| const a = document.createElement('a'); | ||
| try { | ||
| a.href = url; | ||
| a.download = `${config.appName.toLowerCase()}-${invoice.number}.pdf`; | ||
| a.click(); | ||
| } finally { | ||
| a.remove(); | ||
| } | ||
| } finally { | ||
| setTimeout(() => URL.revokeObjectURL(url), 7000); | ||
| } | ||
| }; | ||
|
|
||
| return { onSuccess }; | ||
| } |
34 changes: 34 additions & 0 deletions
34
webapp/src/ee/billing/administration/invoices/AdminDownloadButton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { FC } from 'react'; | ||
|
|
||
| import { components } from 'tg.service/billingApiSchema.generated'; | ||
| import { useBillingApiMutation } from 'tg.service/http/useQueryApi'; | ||
| import { useInvoicePdfDownload } from '../../Invoices/useInvoicePdfDownload'; | ||
| import { PdfDownloadButton } from '../../Invoices/PdfDownloadButton'; | ||
|
|
||
| type AdminDownloadButtonProps = { | ||
| invoice: components['schemas']['InvoiceModel']; | ||
| }; | ||
|
|
||
| export const AdminDownloadButton: FC<AdminDownloadButtonProps> = ({ | ||
| invoice, | ||
| }) => { | ||
| const { onSuccess } = useInvoicePdfDownload(invoice); | ||
|
|
||
| const pdfMutation = useBillingApiMutation({ | ||
| url: '/v2/administration/billing/invoices/{invoiceId}/pdf', | ||
| method: 'get', | ||
| fetchOptions: { rawResponse: true }, | ||
| }); | ||
|
|
||
| const onDownload = () => { | ||
| pdfMutation.mutate({ path: { invoiceId: invoice.id } }, { onSuccess }); | ||
| }; | ||
|
|
||
| return ( | ||
| <PdfDownloadButton | ||
| invoice={invoice} | ||
| onDownload={onDownload} | ||
| isLoading={pdfMutation.isLoading} | ||
| /> | ||
| ); | ||
| }; |
76 changes: 76 additions & 0 deletions
76
webapp/src/ee/billing/administration/invoices/AdminInvoiceUsage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { | ||
| Box, | ||
| DialogContent, | ||
| DialogTitle, | ||
| IconButton, | ||
| Tooltip, | ||
| } from '@mui/material'; | ||
| import { PieChart01 } from '@untitled-ui/icons-react'; | ||
| import { FC, useState } from 'react'; | ||
| import { components } from 'tg.service/billingApiSchema.generated'; | ||
| import { useTranslate } from '@tolgee/react'; | ||
| import { useBillingApiQuery } from 'tg.service/http/useQueryApi'; | ||
| import Dialog from '@mui/material/Dialog'; | ||
| import { EmptyListMessage } from 'tg.component/common/EmptyListMessage'; | ||
| import { TotalTable } from '../../common/usage/TotalTable'; | ||
| import { UsageTable } from '../../common/usage/UsageTable'; | ||
|
|
||
| export const AdminInvoiceUsage: FC<{ | ||
| invoice: components['schemas']['InvoiceModel']; | ||
| }> = ({ invoice }) => { | ||
| const { t } = useTranslate(); | ||
| const [open, setOpen] = useState(false); | ||
|
|
||
| const usage = useBillingApiQuery({ | ||
| url: '/v2/administration/billing/invoices/{invoiceId}/usage', | ||
| method: 'get', | ||
| path: { | ||
| invoiceId: invoice.id, | ||
| }, | ||
| options: { | ||
| enabled: open, | ||
| }, | ||
| }); | ||
|
|
||
| return ( | ||
| <> | ||
| {invoice.hasUsage && ( | ||
| <> | ||
| <Box> | ||
| <IconButton | ||
| size="small" | ||
| onClick={() => setOpen(true)} | ||
| aria-label={t('billing_invoices_show_usage_button')} | ||
| > | ||
| <Tooltip title={t('billing_invoices_show_usage_button')}> | ||
| <PieChart01 /> | ||
| </Tooltip> | ||
| </IconButton> | ||
| </Box> | ||
| <Dialog open={open} onClose={() => setOpen(false)} maxWidth="md"> | ||
| <DialogTitle>{t('invoice_usage_dialog_title')}</DialogTitle> | ||
dkrizan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <DialogContent> | ||
| {usage.data ? ( | ||
| <> | ||
| <UsageTable | ||
| usageData={usage.data} | ||
| invoiceId={invoice.id} | ||
| invoiceNumber={invoice.number} | ||
| organizationId={invoice.organizationId} | ||
| /> | ||
dkrizan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <TotalTable | ||
| invoice={invoice} | ||
| totalWithoutVat={usage.data.total} | ||
| appliedStripeCredits={usage.data.appliedStripeCredits} | ||
| /> | ||
| </> | ||
| ) : ( | ||
| <EmptyListMessage loading={usage.isLoading} /> | ||
| )} | ||
| </DialogContent> | ||
| </Dialog> | ||
| </> | ||
| )} | ||
| </> | ||
| ); | ||
| }; | ||
39 changes: 39 additions & 0 deletions
39
webapp/src/ee/billing/administration/invoices/AdministrationInvoicesView.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { styled } from '@mui/material'; | ||
| import { useTranslate } from '@tolgee/react'; | ||
|
|
||
| import { DashboardPage } from 'tg.component/layout/DashboardPage'; | ||
| import { LINKS } from 'tg.constants/links'; | ||
| import { BaseAdministrationView } from 'tg.views/administration/components/BaseAdministrationView'; | ||
| import { CarryOversSection } from './CarryOversSection'; | ||
| import { OrgInvoicesSection } from './OrgInvoicesSection'; | ||
|
|
||
| const StyledWrapper = styled('div')` | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 40px; | ||
| `; | ||
|
|
||
| export const AdministrationInvoicesView = () => { | ||
| const { t } = useTranslate(); | ||
|
|
||
| return ( | ||
| <DashboardPage> | ||
| <BaseAdministrationView | ||
| windowTitle={t('administration_invoices', 'Invoices')} | ||
| navigation={[ | ||
| [ | ||
| t('administration_invoices'), | ||
| LINKS.ADMINISTRATION_BILLING_INVOICES.build(), | ||
| ], | ||
| ]} | ||
dkrizan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| allCentered | ||
| hideChildrenOnLoading={false} | ||
| > | ||
| <StyledWrapper> | ||
| <OrgInvoicesSection /> | ||
| <CarryOversSection /> | ||
| </StyledWrapper> | ||
| </BaseAdministrationView> | ||
| </DashboardPage> | ||
| ); | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.