mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 23:17:12 +01:00
switch to prisma
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import Input from '../../../../components/input'
|
||||
import Select from '../../../../components/select'
|
||||
import { Booking } from '../../../../db/booking'
|
||||
import { BILL_STATUS, MILAGE_TARIFS } from '../../../../db/enums'
|
||||
import { Booking, Bill, BillStatus, AdditionalCosts, Prisma } from '@prisma/client'
|
||||
import { MILAGE_TARIFS } from '../../../../db/enums'
|
||||
import { getMilageMax } from '../../../../db/index'
|
||||
import { daysFormatFrontend } from '../../../../helpers/date'
|
||||
import { dateFormatFrontend } from '../../../../helpers/date'
|
||||
import { log } from '../../../../helpers/log'
|
||||
import { getBillTotal, createBill, patchBill } from '../../../../helpers/bill'
|
||||
import { getBookingStatus } from '../../../../helpers/booking'
|
||||
@@ -29,7 +29,7 @@ const milageTarifOptions = Object.values(MILAGE_TARIFS).map((tarif) => {
|
||||
)
|
||||
})
|
||||
|
||||
const billStatusOptions = Object.values(BILL_STATUS).map((status) => {
|
||||
const billStatusOptions = Object.values(BillStatus).map((status) => {
|
||||
return (
|
||||
<option value={status} key={status}>
|
||||
{getBillStatusLabel(status)}
|
||||
@@ -50,13 +50,13 @@ function getTarifLabel(tarif: MILAGE_TARIFS) {
|
||||
}
|
||||
}
|
||||
|
||||
function getBillStatusLabel(status: BILL_STATUS) {
|
||||
function getBillStatusLabel(status: BillStatus) {
|
||||
switch (status) {
|
||||
case BILL_STATUS.UNINVOICED:
|
||||
case BillStatus.UNINVOICED:
|
||||
return 'Nicht gestellt'
|
||||
case BILL_STATUS.INVOICED:
|
||||
case BillStatus.INVOICED:
|
||||
return 'Gestellt'
|
||||
case BILL_STATUS.PAID:
|
||||
case BillStatus.PAID:
|
||||
return 'Bezahlt'
|
||||
default:
|
||||
return 'Unbekannt!!!'
|
||||
@@ -67,7 +67,7 @@ function BookingBillPage({
|
||||
booking: bookingProp,
|
||||
milageMax,
|
||||
}: {
|
||||
booking: Booking
|
||||
booking: Booking & { bill: Bill }
|
||||
milageMax: number
|
||||
}) {
|
||||
const [booking, setBooking] = useState(bookingProp)
|
||||
@@ -75,11 +75,11 @@ function BookingBillPage({
|
||||
booking?.bill?.milageStart || milageMax
|
||||
)
|
||||
const [milageEnd, setMilageEnd] = useState(booking?.bill?.milageEnd)
|
||||
const [tarif, setTarif] = useState(
|
||||
booking?.bill?.tarif || MILAGE_TARIFS.EXTERN
|
||||
const [tarif, setTarif] = useState<Prisma.Decimal>(
|
||||
booking?.bill?.tarif
|
||||
)
|
||||
const [status, setStatus] = useState(booking?.bill?.status)
|
||||
const [additionalCosts, setAdditionalCosts] = useState([])
|
||||
const [additionalCosts, setAdditionalCosts] = useState<Prisma.AdditionalCostsCreateInput[]>([])
|
||||
const [storingInProgress, setStoringInProgress] = useState(false)
|
||||
const [storingError, setStoringError] = useState(null)
|
||||
const milage =
|
||||
@@ -99,10 +99,9 @@ function BookingBillPage({
|
||||
const bill = await saveBill(booking.uuid, {
|
||||
milageStart,
|
||||
milageEnd,
|
||||
milage,
|
||||
tarif,
|
||||
status,
|
||||
additionalCosts,
|
||||
additionalCosts: { create: additionalCosts },
|
||||
})
|
||||
|
||||
booking.bill = bill
|
||||
@@ -118,7 +117,7 @@ function BookingBillPage({
|
||||
event: React.MouseEvent<HTMLButtonElement>
|
||||
) {
|
||||
event.preventDefault()
|
||||
setAdditionalCosts([...additionalCosts, { name: '', value: 0 }])
|
||||
setAdditionalCosts([...additionalCosts, { name: '', value: new Prisma.Decimal(0) } as AdditionalCosts])
|
||||
}
|
||||
|
||||
const onRemoveAdditionalCost = function(
|
||||
@@ -138,7 +137,7 @@ function BookingBillPage({
|
||||
<form className="w-full" onSubmit={onSubmit}>
|
||||
<div>
|
||||
<strong>Buchungszeitraum:</strong>{' '}
|
||||
{daysFormatFrontend(booking.days)}
|
||||
{dateFormatFrontend(new Date(booking.startDate))}-{dateFormatFrontend(new Date(booking.endDate))}
|
||||
</div>
|
||||
<div>
|
||||
<strong>Bucher:</strong> {booking.name}
|
||||
@@ -171,8 +170,8 @@ function BookingBillPage({
|
||||
<Select
|
||||
label="Rate"
|
||||
name="tarif"
|
||||
value={tarif}
|
||||
onChange={(e) => setTarif(e.target.value as MILAGE_TARIFS)}
|
||||
value={tarif.toString()}
|
||||
onChange={(e) => setTarif(new Prisma.Decimal(e.target.value))}
|
||||
>
|
||||
{milageTarifOptions}
|
||||
</Select>
|
||||
@@ -211,7 +210,7 @@ function BookingBillPage({
|
||||
newAdditonalCosts[index] = {
|
||||
value: newAdditonalCosts[index].value,
|
||||
name: event.target.value,
|
||||
}
|
||||
} as AdditionalCosts
|
||||
setAdditionalCosts(newAdditonalCosts)
|
||||
}}
|
||||
/>
|
||||
@@ -219,13 +218,13 @@ function BookingBillPage({
|
||||
label={`Betrag`}
|
||||
name={`additionalCostValue${index}`}
|
||||
key={`additionalCostValue${index}`}
|
||||
value={additionalCosts[index].value}
|
||||
value={additionalCosts[index].value.toString()}
|
||||
type="number"
|
||||
onChange={(event) => {
|
||||
const newAdditonalCosts = [...additionalCosts]
|
||||
newAdditonalCosts[index] = {
|
||||
name: newAdditonalCosts[index].name,
|
||||
value: Number(event.target.value),
|
||||
value: new Prisma.Decimal(event.target.value),
|
||||
}
|
||||
setAdditionalCosts(newAdditonalCosts)
|
||||
}}
|
||||
@@ -234,13 +233,13 @@ function BookingBillPage({
|
||||
</>
|
||||
)
|
||||
})}
|
||||
<Input label="Summe" name="total" readOnly value={total} />
|
||||
<Input label="Summe" name="total" readOnly value={total.toString()} />
|
||||
</div>
|
||||
<Select
|
||||
label="Status"
|
||||
name={status}
|
||||
value={status}
|
||||
onChange={(e) => setStatus(e.target.value as BILL_STATUS)}
|
||||
onChange={(e) => setStatus(e.target.value as BillStatus)}
|
||||
>
|
||||
{billStatusOptions}
|
||||
</Select>
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { useRouter } from 'next/router'
|
||||
import { BookingStatus, Booking } from '@prisma/client'
|
||||
import Link from 'next/link'
|
||||
import Calendar from '../../../../components/calendar'
|
||||
import { getServerSideBooking } from '../../../../lib/getServerSideProps'
|
||||
import { Booking } from '../../../../db/booking'
|
||||
import { getBookingStatus, patchBooking } from '../../../../helpers/booking'
|
||||
import { daysFormatFrontend } from '../../../../helpers/date'
|
||||
import { log } from '../../../../helpers/log'
|
||||
import { BOOKING_STATUS } from '../../../../db/enums'
|
||||
|
||||
export const getServerSideProps = getServerSideBooking
|
||||
|
||||
@@ -25,7 +24,7 @@ function ShowBookingAdmin({ booking: bookingProp }: { booking: Booking }) {
|
||||
setStoringBookingError(null)
|
||||
setStoringBooking(true)
|
||||
const updatedBooking = await patchBooking(booking.uuid, {
|
||||
status: confirmed ? BOOKING_STATUS.CONFIRMED : BOOKING_STATUS.REJECTED,
|
||||
status: confirmed ? BookingStatus.CONFIRMED : BookingStatus.REJECTED,
|
||||
})
|
||||
setBooking(updatedBooking)
|
||||
} catch (error) {
|
||||
@@ -40,7 +39,7 @@ function ShowBookingAdmin({ booking: bookingProp }: { booking: Booking }) {
|
||||
<h2 className="text-3xl">Buchung {booking.uuid}</h2>
|
||||
<Calendar start={booking.startDate} end={booking.endDate} />
|
||||
<div>
|
||||
<strong>Buchungszeitraum:</strong> {daysFormatFrontend(booking.days)}
|
||||
<strong>Buchungszeitraum:</strong> {daysFormatFrontend([booking.startDate])}-{daysFormatFrontend([booking.endDate])}
|
||||
</div>
|
||||
<div>
|
||||
<strong>Bucher:</strong> {booking.name}
|
||||
|
||||
Reference in New Issue
Block a user