From a827f46f0fca0d0c5e198af36eb96dabfbb9c7a3 Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Tue, 4 Apr 2023 11:52:21 +0000 Subject: [PATCH] chore(letter): implement course qualification letter (wip) --- src/Handler/SAP.hs | 12 +++--- src/Handler/Utils/Profile.hs | 17 ++++++--- src/Model/Types/DateTime.hs | 14 +++++++ src/Utils/Lens.hs | 3 ++ src/Utils/Print.hs | 1 + src/Utils/Print/RenewQualification.hs | 2 +- templates/letter/fraport_qualification.md | 45 ++++++++++++++++++++++- 7 files changed, 81 insertions(+), 13 deletions(-) diff --git a/src/Handler/SAP.hs b/src/Handler/SAP.hs index 368baebbf..5365b00fd 100644 --- a/src/Handler/SAP.hs +++ b/src/Handler/SAP.hs @@ -13,6 +13,7 @@ import Import import Handler.Utils import Handler.Utils.Csv +import Handler.Utils.Profile -- import qualified Data.CaseInsensitive as CI import qualified Data.Csv as Csv @@ -56,11 +57,11 @@ instance ToNamedRecord SapUserTableCsv where -- | Removes all personalNummer which are not numbers between 10000 and 99999 (also excludes E-Accounts), which should not be returned by the query anyway (only qualfications with sap id and users with internal personnel number must be transmitted) -- TODO: once temporary suspensions are implemented, a user must be transmitted to SAP in two rows: firstheld->suspensionFrom & suspensionTo->validTo sapRes2csv :: [(Ex.Value (Maybe Text), Ex.Value Day, Ex.Value Day, Ex.Value (Maybe Text))] -> [SapUserTableCsv] -sapRes2csv l = [ res | (Ex.Value (Just persNo), Ex.Value firstHeld, Ex.Value validUntil, Ex.Value (Just sapId)) <- l - , let persNoAsInt = readMay persNo - , persNoAsInt >= Just (10000::Int) -- filter E-accounts for SAP export - , persNoAsInt <= Just (99999::Int) -- filter E-accounts for SAP export - , let res = SapUserTableCsv +sapRes2csv l = [ res | (Ex.Value pn@(Just persNo), Ex.Value firstHeld, Ex.Value validUntil, Ex.Value (Just sapId)) <- l + -- , let persNoAsInt = readMay =<< persNo -- also see Handler.Utils.Profile.validFraportPersonalNumber + -- , persNoAsInt >= Just (10000::Int) -- filter E-accounts for SAP export + -- , persNoAsInt <= Just (99999::Int) -- filter E-accounts for SAP export + , let res = SapUserTableCsv { csvSUTpersonalNummer = persNo , csvSUTqualifikation = sapId , csvSUTgültigVon = firstHeld @@ -68,6 +69,7 @@ sapRes2csv l = [ res | (Ex.Value (Just persNo), Ex.Value firstHeld, Ex.Value val -- , csvSUTsupendiertBis = blocked , csvSUTausprägung = "J" } + , validFraportPersonalNumber pn ] -- | Deliver all employess with a successful LDAP synch within the last 3 months diff --git a/src/Handler/Utils/Profile.hs b/src/Handler/Utils/Profile.hs index 22f7a8098..d473bd54d 100644 --- a/src/Handler/Utils/Profile.hs +++ b/src/Handler/Utils/Profile.hs @@ -5,12 +5,10 @@ -- TODO: why is this Handler.Utils.Profile instead of Utils.Profile? -- TODO: consider merging with Handler.Utils.Users? module Handler.Utils.Profile - ( checkDisplayName - , validDisplayName - , fixDisplayName + ( validDisplayName, checkDisplayName, fixDisplayName , validPostAddress - , validEmail, validEmail' - , pickValidEmail, pickValidEmail' + , validEmail, validEmail', pickValidEmail, pickValidEmail' + , validFraportPersonalNumber ) where import Import.NoFoundation @@ -103,4 +101,11 @@ pickValidEmail' :: UserEmail -> UserEmail -> Maybe UserEmail pickValidEmail' x y | validEmail' x = Just x | validEmail' y = Just y - | otherwise = Nothing \ No newline at end of file + | otherwise = Nothing + +validFraportPersonalNumber :: Maybe Text -> Bool +validFraportPersonalNumber Nothing = False +validFraportPersonalNumber (Just t) + | (Just pn) <- readMay t + = pn >= (10000::Int) && pn <= (99999::Int) -- used to filter for SAP export + | otherwise = False diff --git a/src/Model/Types/DateTime.hs b/src/Model/Types/DateTime.hs index a3ffb0ff6..f36420657 100644 --- a/src/Model/Types/DateTime.hs +++ b/src/Model/Types/DateTime.hs @@ -15,6 +15,7 @@ module Model.Types.DateTime import Import.NoModel +import qualified Data.Set as Set import Data.Ratio ((%)) import qualified Data.Text as Text -- import Data.Either.Combinators (maybeToRight, mapLeft) @@ -206,3 +207,16 @@ derivePersistFieldJSON ''Occurrences nullaryPathPiece ''DayOfWeek camelToPathPiece + + +-- | Get bounds for an Occurrences +-- TODO: unfinished function, only works for a few selected cases yet +occurrencesBounds :: Occurrences -> (Maybe Day, Maybe Day) +occurrencesBounds Occurrences{occurrencesScheduled=scd} | notNull scd = (Nothing, Nothing) -- TODO: case is not yet implemented +occurrencesBounds Occurrences{occurrencesExceptions=exc} = (Set.lookupMin occDays, Set.lookupMax occDays) + where + occDays = Set.foldr getOccDays mempty exc + + getOccDays :: OccurrenceException -> Set Day -> Set Day + getOccDays ExceptNoOccur{} acc = acc -- TODO: this case ignores ExceptNoOccur for now! + getOccDays ExceptOccur{exceptDay} acc = Set.insert exceptDay acc diff --git a/src/Utils/Lens.hs b/src/Utils/Lens.hs index aaa7aa63a..8d8108ee5 100644 --- a/src/Utils/Lens.hs +++ b/src/Utils/Lens.hs @@ -128,6 +128,9 @@ makeClassyFor_ ''LmsResult makeClassyFor_ ''UserAvs makeClassyFor_ ''UserAvsCard +makeClassyFor_ ''UserCompany +makeLenses_ ''Company + _entityKey :: Getter (Entity record) (Key record) -- ^ Not a `Lens'` for safety _entityKey = to entityKey diff --git a/src/Utils/Print.hs b/src/Utils/Print.hs index 55b81a0c8..7d2d46374 100644 --- a/src/Utils/Print.hs +++ b/src/Utils/Print.hs @@ -47,6 +47,7 @@ import Jobs.Handler.SendNotification.Utils import Utils.Print.Letters import Utils.Print.RenewQualification +import Utils.Print.CourseCertificate -- import Model.Types.Markup -- TODO-QSV: should this module be moved accordingly? diff --git a/src/Utils/Print/RenewQualification.hs b/src/Utils/Print/RenewQualification.hs index 55496a840..f8228e036 100644 --- a/src/Utils/Print/RenewQualification.hs +++ b/src/Utils/Print/RenewQualification.hs @@ -1,4 +1,4 @@ --- SPDX-FileCopyrightText: 2022 Steffen Jost +-- SPDX-FileCopyrightText: 2023 Steffen Jost -- -- SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/templates/letter/fraport_qualification.md b/templates/letter/fraport_qualification.md index c29c2deb0..2b75d9571 100644 --- a/templates/letter/fraport_qualification.md +++ b/templates/letter/fraport_qualification.md @@ -8,8 +8,51 @@ date: 11.11.1111 ... $if(is-de)$ +# Teilnahmebescheinigung + +## $participant$ + +$if(fra-number)$ + ### $fra-number$ $fra-department$ +$endif$ + +$if(company)$ + ### $company$ +$endif$ + +Hat +$if(course-begin)$ +von $course-begin$ bis $course-end$ +$endif$ +an der Veranstaltung + +## $course-name$ + +der Fahrerausbildung der Fraport AG teilgenommen. + +$if(course-content)$ + ### Inhalte: + + $course-content$ +$endif$ + +Mit Aushändigung der Teilnahmebescheinigung wird der erfolgreiche Abschluss des Kurses bestätigt. +Dieses Zertifikat wurde maschinell erstellt. + + +Frankfurt am Main, $date$ + +Fraport College + $else$ - \ No newline at end of file + + +# Certificate of attendance + +**English version is not yet implemened.** +TODO + +$endif$ \ No newline at end of file