diff --git a/src/Utils/Print/Letters.hs b/src/Utils/Print/Letters.hs index 0718a294b..f645772c9 100644 --- a/src/Utils/Print/Letters.hs +++ b/src/Utils/Print/Letters.hs @@ -177,17 +177,30 @@ data PrintJobIdentification = PrintJobIdentification -- this is printed in white on white at the exact same position on the page -- Note: that all letters to the same UUID within 24h are collated in one envelope -- Example: 9ad8de3f-0a7e-ede5-bd8b-6d0ed85c1049-f___a4pin___230322-10___lms-stuvwxyz -mkApcIdent :: CryptoUUIDUser -> Char -> LetterKind -> Text -> Text -> Text +mkApcIdent :: CryptoUUIDUser -> (Int, Char) -> LetterKind -> Text -> Text -> Text mkApcIdent uuid envelope lk tnow apcAck = Text.filter apcAcceptedChars $ Text.intercalate apcIdentSeparator - [ ensureLength 38 $ tshow (ciphertext uuid) <> Text.cons '-' (Text.singleton envelope) + [ ensureLength 38 $ tshow (ciphertext uuid) <> mkEnvelope envelope , ensureLength 5 $ paperKind lk , ensureLength 9 tnow , Text.take 32 apcAck -- length of last part may be arbitrary, but more than 32 symbols do not fit into the line ] - where + where ensureLength :: Int -> Text -> Text ensureLength n = Text.take n . Text.justifyLeft n 'x' +mkEnvelope :: (Int, Char) -> Text +mkEnvelope (i,c) = Text.cons (pfx $ i `mod` 63) $ Text.singleton sfx + where + pfx n + | n <= 0 = Text.cons '-' $ Text.singleton c + | n <= 10 = Text.cons (chr $ ord '0' + n `mod` 10) + | n <= 36 = Text.cons (chr $ ord 'a' + n - 11) + | n <= 62 = Text.cons (chr $ ord 'A' + n - 37) + | otherwise = Text.cons '-' $ Text.singleton c + sfx + | n <= 62 = c + | otherwise = Char.toUpper c + formatApcIdentTime :: (HasLocalTime t, MonadHandler m) => t -> m Text formatApcIdentTime = formatTime' "%y%m%d-%H" @@ -245,7 +258,10 @@ letterApcIdent :: (MDLetter l, MonadHandler m) => l -> CryptoUUIDUser -> UTCTime letterApcIdent l uuid now = do -- now <- liftIO getCurrentTime tnow <- formatApcIdentTime now - return $ mkApcIdent uuid (getLetterEnvelope l) (getLetterKind l) tnow (pjiApcAcknowledge $ getPJId l) + let startEnvelope = (0, getLetterEnvelope l) + mkApcEnv env = mkApcIdent uuid env (getLetterKind l) tnow (pjiApcAcknowledge $ getPJId l) + -- TODO: turn this into a loop increasing the number for each 6 unacknowledged letters to the first part of the ident only + return $ mkApcEnv startEnvelope letterFileName :: (MDLetter l) => l -> FilePath letterFileName = Text.unpack . (<> ".pdf") . text2asciiAlphaNum . pjiFileName . getPJId