SELECT customer travel card information
Sometimes we need to send a report to a client where they need the following details of their customers from the tms_booking database: (Note that a customer may have multiple customer transport accounts) * First name * Last name * Travel card number * Travel card validity begin date * Travel card validity end date * Travel card termination status * Travel card blacklist status * Travel card description * Customer transport account (CTA) account type * "matkatili" * CTA copayment exemption status * "vapautettu omavastuusta valintapainike" * CTA copayment type * "omavastuun tyyppi" * CTA validity begin date * CTA validity end date
Warning: This data is quite sensitive and should be handled with GDPR laws in mind!
Here is the Postgres query to do so in tms_booking:
SELECT
customer.index as c_index,
customer.uuid AS c_uuid,
customer.org_index AS c_org_index,
customer.details->'name_first' AS c_first_name,
customer.details->'name_last' AS c_last_name,
customers_cards.index AS cc_index,
customers_cards.uuid AS cc_uuid,
customers_cards.user_index AS cc_user_index,
customers_cards.card_number AS cc_card_number,
customers_cards.valid_from AS cc_valid_from,
customers_cards.valid_to AS cc_valid_to,
customers_cards.terminated AS cc_terminated,
customers_cards.blacklisted AS cc_blacklisted,
customers_cards.details->'card_black_listed' AS cc_card_black_listed,
customers_cards.description AS cc_description,
customer_transport_account.index AS cta_index,
customer_transport_account.uuid AS cta_uuid,
customer_transport_account.user_index AS cta_user_index,
customer_transport_account.account_type AS cta_account_type,
customer_transport_account.exempt_from_copayment AS cta_exempt_from_copayment,
customer_transport_account.copayment_type AS cta_copayment_type,
customer_transport_account.valid_from AS cta_valid_from,
customer_transport_account.valid_until AS cta_valid_until
FROM customer
LEFT JOIN customers_cards ON customer.index = customers_cards.user_index
JOIN customer_transport_account ON customer.index = customer_transport_account.user_index
WHERE customer.org_index = CUSTOMER_ORG_INDEX
How to safely send this data:
1. Save the data in a format that allows password-protection, for example .xlsx (Libreoffice Calc can do this)
2. Send the password-protected file via a method that allows whitelisting to certain people, for example Google Drive.