mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 18:48:11 +00:00
Payment discrepancy report updates
This commit is contained in:
@@ -412,7 +412,9 @@ export class ReportsService {
|
||||
}
|
||||
|
||||
async listSchedulesForPicker() {
|
||||
const now = new Date();
|
||||
const schedules = await this.prisma.trainSchedule.findMany({
|
||||
where: { departureAt: { gte: now } },
|
||||
select: {
|
||||
id: true,
|
||||
departureAt: true,
|
||||
@@ -420,12 +422,13 @@ export class ReportsService {
|
||||
originStation: { select: { name: true } },
|
||||
destinationStation: { select: { name: true } },
|
||||
},
|
||||
orderBy: { departureAt: "desc" },
|
||||
orderBy: { departureAt: 'asc' },
|
||||
take: 200,
|
||||
});
|
||||
return schedules.map((s) => ({
|
||||
id: s.id,
|
||||
label: `${s.train.number} · ${s.originStation.name} → ${s.destinationStation.name} · ${new Date(s.departureAt).toLocaleString("en-GB", { dateStyle: "medium", timeStyle: "short" })}`,
|
||||
departureAt: s.departureAt,
|
||||
label: `${s.train.number} · ${s.originStation.name} → ${s.destinationStation.name} · ${new Date(s.departureAt).toLocaleString('en-GB', { dateStyle: 'medium', timeStyle: 'short' })}`,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -926,7 +929,8 @@ export class ReportsService {
|
||||
seat: {
|
||||
select: {
|
||||
seatNumber: true,
|
||||
coach: { select: { number: true, coachType: { select: { name: true } } } },
|
||||
bedPosition: true,
|
||||
coach: { select: { number: true, coachType: { select: { name: true, seatClasses: { select: { name: true, bedPosition: true } } } } } },
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -935,30 +939,26 @@ export class ReportsService {
|
||||
},
|
||||
});
|
||||
|
||||
const resolveSeatClass = (seat: any): string => {
|
||||
const classes = seat?.coach?.coachType?.seatClasses ?? [];
|
||||
const matched = seat?.bedPosition
|
||||
? classes.find((sc: any) => sc.bedPosition?.toLowerCase() === seat.bedPosition.toLowerCase())
|
||||
: null;
|
||||
return (matched ?? classes[0])?.name ?? seat?.coach?.coachType?.name ?? 'Unknown';
|
||||
};
|
||||
|
||||
let rows = bookings.map(b => {
|
||||
const pi = b.paymentIntent!;
|
||||
const actualMinor = b.seats.reduce((s, seat) => s + (seat.fareMinor ?? 0), 0);
|
||||
const paidMinor = Math.round(pi.amountMinor);
|
||||
const varianceMinor = actualMinor - paidMinor;
|
||||
|
||||
// Per-seat-class breakdown
|
||||
const byClass = new Map<string, { seatClass: string; coachNumber: string | null; seatNumber: string | null; fareMinor: number }[]>();
|
||||
for (const s of b.seats) {
|
||||
const key = s.seatLabelSnapshot ?? s.seat?.coach?.coachType?.name ?? 'Unknown';
|
||||
if (!byClass.has(key)) byClass.set(key, []);
|
||||
byClass.get(key)!.push({
|
||||
seatClass: key,
|
||||
coachNumber: s.seat?.coach?.number ?? null,
|
||||
seatNumber: s.seat?.seatNumber ?? null,
|
||||
fareMinor: s.fareMinor ?? 0,
|
||||
});
|
||||
}
|
||||
|
||||
const breakdown = [...byClass.entries()].map(([seatClass, seats]) => ({
|
||||
seatClass,
|
||||
seats: seats.map(s => ({ coachNumber: s.coachNumber, seatNumber: s.seatNumber })),
|
||||
totalFareMinor: seats.reduce((s, x) => s + x.fareMinor, 0),
|
||||
count: seats.length,
|
||||
const breakdown = b.seats.map(s => ({
|
||||
passengerName: s.passengerName ?? '—',
|
||||
seatClass: resolveSeatClass(s.seat),
|
||||
coachNumber: s.seat?.coach?.number ?? null,
|
||||
seatNumber: s.seat?.seatNumber ?? null,
|
||||
fareMinor: s.fareMinor ?? 0,
|
||||
}));
|
||||
|
||||
const firstSeat = b.seats[0];
|
||||
|
||||
Reference in New Issue
Block a user