File indexing completed on 2024-12-29 04:51:05

0001 /*
0002    SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003    SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 function cleanText(s)
0007 {
0008     return s.replace(/<(\d+)>/g, (_,n)=>' ąćęłńóśźżĄĆĘŁŃÓŚŹŻ'[n]);
0009 }
0010 
0011 // see https://community.kde.org/KDE_PIM/KItinerary/PKP_Barcode
0012 function parseBarcode(content, node) {
0013     const layout = content.ticketLayout;
0014     let res = JsonLd.newTrainReservation();
0015     res.reservedTicket = node.result[0];
0016     res.reservedTicket.issuedBy = undefined; // invalid UIC company code
0017     res.reservedTicket.name = cleanText(layout.text(2, 0, 72, 1));
0018     res.reservationFor.departureTime = JsonLd.toDateTime(layout.text(10, 0, 72, 1) + ' ' + layout.text(11, 0, 72, 1), 'hh:mm dd.MM', 'pl');
0019     res.reservationFor.arrivalTime = JsonLd.toDateTime(layout.text(14, 0, 72, 1) + ' ' + layout.text(15, 0, 72, 1), 'hh:mm dd.MM', 'pl');
0020     res.reservedTicket.ticketedSeat = JsonLd.newObject('Seat');
0021     res.reservedTicket.ticketedSeat.seatingType = layout.text(16, 0, 72, 1);
0022     res.reservationFor.trainNumber = layout.text(18, 0, 72, 1);
0023     res.reservedTicket.ticketedSeat.seatNumber = cleanText(layout.text(23, 0, 72, 1));
0024     res.reservationNumber = layout.text(31, 0, 72, 1);
0025     res.reservationFor.departureStation.name = layout.text(41, 0, 72, 1);
0026     res.reservationFor.departureStation.identifier = 'pl:' + layout.text(12, 0, 72, 1);
0027     res.reservationFor.arrivalStation.name = layout.text(42, 0, 72, 1);
0028     res.reservationFor.arrivalStation.identifier = 'pl:' + layout.text(13, 0, 72, 1);
0029     res.totalPrice = layout.text(26, 0, 72, 1) / 100;
0030     res.priceCurrency = 'PLN';
0031     return res;
0032 }