Skip to content

Commit

Permalink
Merge pull request #44 from konsept-ch/invoices/add-type-and-reason
Browse files Browse the repository at this point in the history
add invoice type and reason
  • Loading branch information
maieutiquer authored Feb 12, 2023
2 parents ad092d1 + 563a757 commit a3a9f12
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 22 deletions.
65 changes: 54 additions & 11 deletions src/components/ManualInvoiceModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ const tvaOptions = [
]
// const defaultTvaOption = tvaOptions[1]

const unitValues = [
const unitOptions = [
{ value: 'jour(s)', label: 'jour(s)' },
{ value: 'heure(s)', label: 'heure(s)' },
{ value: 'forfait(s)', label: 'forfait(s)' },
{ value: 'part.', label: 'part.' },
]

export function ManualInvoiceModal({
refetchInvoices,
selectedInvoiceData,
Expand All @@ -41,9 +40,10 @@ export function ManualInvoiceModal({
organizations,
fetchUsers,
users,
fetchStatuses,
statuses,
fetchEnums,
enums,
}) {
const { invoiceStatuses, invoiceTypes, invoiceReasons } = enums ?? {}
const {
control,
register,
Expand Down Expand Up @@ -112,13 +112,35 @@ export function ManualInvoiceModal({

const statusesOptions = useMemo(
() =>
statuses != null
? Object.entries(statuses).map(([prismaStatus, actualStatus]) => ({
invoiceStatuses != null
? Object.entries(invoiceStatuses).map(([prismaStatus, actualStatus]) => ({
value: prismaStatus,
label: actualStatus,
}))
: null,
[statuses]
[invoiceStatuses]
)

const invoiceTypeOptions = useMemo(
() =>
invoiceTypes != null
? Object.entries(invoiceTypes).map(([prismaInvoiceType, actualInvoiceType]) => ({
value: prismaInvoiceType,
label: actualInvoiceType,
}))
: null,
[invoiceTypes]
)

const reasonOptions = useMemo(
() =>
invoiceReasons != null
? Object.entries(invoiceReasons).map(([prismaInvoiceReason, actualInvoiceReason]) => ({
value: prismaInvoiceReason,
label: actualInvoiceReason,
}))
: null,
[invoiceReasons]
)

const userOptions = useMemo(
Expand All @@ -135,7 +157,6 @@ export function ManualInvoiceModal({
if (selectedInvoiceData != null) {
const {
organizationUuid,
// invoiceNumberForCurrentYear,
customClientEmail,
customClientAddress,
customClientTitle,
Expand All @@ -147,13 +168,14 @@ export function ManualInvoiceModal({
selectedUserUuid,
concerns,
status,
invoiceType,
reason,
} = selectedInvoiceData

reset({
client: clientOptions?.find(({ uuid }) => uuid === organizationUuid),
selectedUser: userOptions?.find(({ uuid }) => uuid === selectedUserUuid),
status: statusesOptions?.find(({ label }) => label === status),
// status: { value: status, label: statuses?.[status] },
customClientAddress,
customClientEmail,
customClientTitle,
Expand All @@ -163,6 +185,8 @@ export function ManualInvoiceModal({
invoiceDate: new Date(String(invoiceDate)),
items,
concerns,
invoiceType: invoiceTypeOptions?.find(({ label }) => label === invoiceType),
reason: reasonOptions?.find(({ label }) => label === reason),
})
} else {
reset({
Expand All @@ -174,6 +198,9 @@ export function ManualInvoiceModal({
customClientLastname: '',
courseYear: '',
invoiceDate: '',
concerns: '',
invoiceType: invoiceTypeOptions?.find(({ label }) => label === 'Manuelle'),
reason: reasonOptions?.find(({ label }) => label === 'Participation'),
items: [defaultEmptyItem],
status: statusesOptions?.find(({ label }) => label === 'En préparation'),
})
Expand All @@ -183,7 +210,7 @@ export function ManualInvoiceModal({
useEffect(() => {
if (isModalOpen) {
fetchOrganizations()
fetchStatuses()
fetchEnums()
}
}, [isModalOpen])

Expand Down Expand Up @@ -225,6 +252,22 @@ export function ManualInvoiceModal({
) : (
'Chargement des statuts...'
)}
<Form.Group className="mb-3" controlId="invoiceType">
<Form.Label>Type de facture</Form.Label>
<Controller
name="invoiceType"
control={control}
render={({ field }) => <Select {...field} options={invoiceTypeOptions} />}
/>
</Form.Group>
<Form.Group className="mb-3" controlId="reason">
<Form.Label>Type de facture</Form.Label>
<Controller
name="reason"
control={control}
render={({ field }) => <Select {...field} options={reasonOptions} />}
/>
</Form.Group>
</Col>
<Col>
<Form.Group className="mb-3" controlId="clientSelect">
Expand Down Expand Up @@ -423,7 +466,7 @@ export function ManualInvoiceModal({
<Controller
name={`items.${index}.unit`}
control={control}
render={({ field }) => <Select {...field} options={unitValues} />}
render={({ field }) => <Select {...field} options={unitOptions} />}
/>
</Col>
<Col>
Expand Down
28 changes: 20 additions & 8 deletions src/pages/ManualInvoicesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faPen } from '@fortawesome/pro-light-svg-icons'

import { Grid, ManualInvoiceModal } from '../components'
import {
useGetManualInvoicesQuery,
useLazyGetStatusesQuery,
useUpdateStatusesMutation,
} from '../services/manual-invoices'
import { useGetManualInvoicesQuery, useLazyGetEnumsQuery, useUpdateStatusesMutation } from '../services/manual-invoices'
import { useLazyGetOrganizationsFlatWithAddressQuery } from '../services/organizations'
import { useLazyGetUsersQuery } from '../services/users'
import { gridContextMenu, downloadCsvFile } from '../utils'
Expand Down Expand Up @@ -40,7 +36,7 @@ export function ManualInvoicesPage() {

const [fetchOrganizations, { data: organizations }] = useLazyGetOrganizationsFlatWithAddressQuery()
const [fetchUsers, { data: users }] = useLazyGetUsersQuery()
const [fetchStatuses, { data: statuses }] = useLazyGetStatusesQuery()
const [fetchEnums, { data: enums }] = useLazyGetEnumsQuery()
const [updateStatuses, { isLoading: isStatusesUpdating }] = useUpdateStatusesMutation()

const {
Expand Down Expand Up @@ -169,6 +165,22 @@ export function ManualInvoicesPage() {
.reduce((a, b) => Number(a) + Number(b), 0)
.toFixed(2),
},
{
field: 'reason',
headerName: 'Raison',
tooltipField: 'reason',
headerTooltip: 'Raison de la facture, utilisé pour les pénalités',
filter: 'agSetColumnFilter',
width: 150,
},
{
field: 'invoiceType',
headerName: 'Type',
tooltipField: 'invoiceType',
headerTooltip: 'Type de la facture, utilisé pour filtrer selon la page',
filter: 'agSetColumnFilter',
width: 150,
},
])

return (
Expand Down Expand Up @@ -364,8 +376,8 @@ export function ManualInvoicesPage() {
organizations={organizations}
fetchUsers={fetchUsers}
users={users}
fetchStatuses={fetchStatuses}
statuses={statuses}
fetchEnums={fetchEnums}
enums={enums}
/>
)}
</>
Expand Down
6 changes: 3 additions & 3 deletions src/services/manual-invoices.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const manualInvoicesApi = createApi({
reducerPath: 'manualInvoicesApi',
baseQuery: prepareBaseQuery({ servicePath: 'manual-invoices' }),
endpoints: (builder) => ({
getStatuses: builder.query({
query: () => 'statuses',
getEnums: builder.query({
query: () => 'enums',
}),
updateStatuses: builder.mutation({
query: ({ body }) => ({
Expand Down Expand Up @@ -43,7 +43,7 @@ export const manualInvoicesApi = createApi({
})

export const {
useLazyGetStatusesQuery,
useLazyGetEnumsQuery,
useUpdateStatusesMutation,
useGetManualInvoicesQuery,
useCreateManualInvoiceMutation,
Expand Down

0 comments on commit a3a9f12

Please sign in to comment.