Report number updates

This commit is contained in:
Stephanos A
2026-07-19 08:07:59 +03:00
parent 4805a54bf7
commit 93c583edf6
4 changed files with 92 additions and 105 deletions

View File

@@ -105,7 +105,7 @@ export class ReportsService {
const tripData = schedules.map(schedule => {
const totalSeats = schedule.coachAssignments.reduce((sum, a) => sum + a.coach.seats.length, 0);
const bookedSeats = schedule.bookings.reduce(
(sum, b) => sum + b.seats.filter((s: any) => s.scheduleId === schedule.id).length, 0,
(sum, b) => sum + b.seats.filter((s: any) => s.leg === 1).length, 0,
);
const occupancyRate = totalSeats > 0 ? (bookedSeats / totalSeats) * 100 : 0;
return { scheduleId: schedule.id, departureAt: schedule.departureAt, totalSeats, bookedSeats, occupancyRate: +occupancyRate.toFixed(2) };
@@ -217,7 +217,7 @@ export class ReportsService {
where: { status: { in: ['CONFIRMED', 'BOARDED'] } },
include: {
seats: {
where: { scheduleId },
where: { leg: 1 },
include: {
seat: { include: { coach: { include: { coachType: true } } } },
},
@@ -313,27 +313,46 @@ export class ReportsService {
async getPassengerList(scheduleId: string) {
const seats = await this.prisma.bookingSeat.findMany({
where: {
scheduleId,
booking: { status: { in: ['CONFIRMED', 'BOARDED'] } },
leg: 1,
booking: { scheduleId, status: { in: ['CONFIRMED', 'BOARDED'] } },
},
include: {
booking: { select: { bookingRef: true, status: true } },
seat: { include: { coach: { select: { number: true, coachType: { select: { name: true } } } } } },
booking: {
select: {
bookingRef: true,
status: true,
originStationId: true,
destinationStationId: true,
},
},
seat: { include: { coach: { select: { number: true } } } },
},
orderBy: [{ seat: { coach: { number: 'asc' } } }],
orderBy: [{ seat: { coach: { number: 'asc' } } }, { seat: { seatNumber: 'asc' } }],
});
// Resolve station names in one query
const stationIds = [...new Set(
seats.flatMap(bs => [bs.booking.originStationId, bs.booking.destinationStationId]).filter(Boolean) as string[],
)];
const stations = stationIds.length > 0
? await this.prisma.station.findMany({ where: { id: { in: stationIds } }, select: { id: true, name: true } })
: [];
const stationName = new Map(stations.map(s => [s.id, s.name]));
const schedule = await this.prisma.trainSchedule.findUnique({
where: { id: scheduleId },
select: { departureAt: true },
});
return seats.map(bs => ({
bookingRef: bs.booking.bookingRef,
bookingStatus: bs.booking.status,
passengerName: bs.passengerName,
passengerCategory: bs.passengerCategory,
idDocumentType: bs.idDocumentType,
idDocumentNumber: bs.idDocumentNumber,
passportNumber: bs.passportNumber,
passportCountry: bs.passportCountry,
seatLabel: bs.seatLabelSnapshot,
coachNumber: bs.seat?.coach?.number ?? null,
coachType: (bs.seat?.coach as any)?.coachType?.name ?? null,
coachSeat: bs.seat?.coach?.number && bs.seatLabelSnapshot
? `${bs.seat.coach.number}·${bs.seatLabelSnapshot}`
: (bs.seatLabelSnapshot ?? '—'),
origin: bs.booking.originStationId ? (stationName.get(bs.booking.originStationId) ?? '—') : '—',
destination: bs.booking.destinationStationId ? (stationName.get(bs.booking.destinationStationId) ?? '—') : '—',
departureAt: schedule?.departureAt ?? null,
}));
}

View File

@@ -600,6 +600,9 @@ export class SeatsService {
async getBlockedSeats() {
const blocks = await this.prisma.seatBlock.findMany({
where: {
NOT: { reason: { startsWith: 'MAINTENANCE:' } },
},
include: {
seat: { include: { coach: { select: { number: true } } } },
},