Skip to content

Commit

Permalink
Merge pull request #45 from konsept-ch/invoices/grouped
Browse files Browse the repository at this point in the history
add buttons for grouped invoice
  • Loading branch information
maieutiquer authored Feb 13, 2023
2 parents 2337b14 + 62562f7 commit 5061cae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/pages/ManualInvoicesPage.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from 'react'
import { useLocation } from 'react-router-dom'
import { Container, Button } from 'react-bootstrap'
import { Helmet } from 'react-helmet-async'
import { toast } from 'react-toastify'
Expand All @@ -8,12 +9,16 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faPen } from '@fortawesome/pro-light-svg-icons'

import { Grid, ManualInvoiceModal } from '../components'
import { useGetManualInvoicesQuery, useLazyGetEnumsQuery, useUpdateStatusesMutation } from '../services/manual-invoices'
import {
useGetManualInvoicesQuery,
useLazyGetEnumsQuery,
useUpdateStatusesMutation,
useGenerateGroupedInvoiceMutation,
} from '../services/manual-invoices'
import { useLazyGetOrganizationsFlatWithAddressQuery } from '../services/organizations'
import { useLazyGetUsersQuery } from '../services/users'
import { gridContextMenu, downloadCsvFile } from '../utils'
import { mapPathnameToInvoiceType } from '../constants/invoices'
import { useLocation } from 'react-router-dom'

const INVOICE_STATUSES = ['En préparation', 'A traiter', 'Exportée', 'Non transmissible', 'Annulée', 'Envoyée']

Expand All @@ -40,6 +45,7 @@ export function ManualInvoicesPage() {
const [fetchUsers, { data: users }] = useLazyGetUsersQuery()
const [fetchEnums, { data: enums }] = useLazyGetEnumsQuery()
const [updateStatuses, { isLoading: isStatusesUpdating }] = useUpdateStatusesMutation()
const [generateGroupedInvoices, { isLoading: isGeneratingGroupedInvoices }] = useGenerateGroupedInvoiceMutation()

const location = useLocation()

Expand Down Expand Up @@ -388,6 +394,20 @@ export function ManualInvoicesPage() {
<Button variant="success" className="me-2" onClick={() => setIsManualInvoiceModalOpen(true)}>
Créer facture manuelle
</Button>
<Button
variant="secondary"
className="me-2"
onClick={() => generateGroupedInvoices({ type: 'semestrial' })}
>
Générer factures sémestrielles {isGeneratingGroupedInvoices && '...'}
</Button>
<Button
variant="secondary"
className="me-2"
onClick={() => generateGroupedInvoices({ type: 'annual' })}
>
Générer factures annuelles {isGeneratingGroupedInvoices && '...'}
</Button>
</Container>
{isManualInvoiceModalOpen && (
<ManualInvoiceModal
Expand Down
8 changes: 8 additions & 0 deletions src/services/manual-invoices.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export const manualInvoicesApi = createApi({
method: 'DELETE',
}),
}),
generateGroupedInvoice: builder.mutation({
query: ({ type }) => ({
url: 'grouped',
method: 'POST',
body: { type },
}),
}),
}),
})

Expand All @@ -49,4 +56,5 @@ export const {
useCreateManualInvoiceMutation,
useUpdateManualInvoiceMutation,
useRemoveManualInvoiceMutation,
useGenerateGroupedInvoiceMutation,
} = manualInvoicesApi

0 comments on commit 5061cae

Please sign in to comment.