diff --git a/code/Angabe4.lhs b/code/Angabe4.lhs index dcdf41e..a4ec56c 100644 --- a/code/Angabe4.lhs +++ b/code/Angabe4.lhs @@ -92,6 +92,102 @@ Helper functions: > month_to_str Nov = "11" > month_to_str Dez = "12" +> day_to_int :: Tag -> Int +> day_to_int I = 1 +> day_to_int II = 2 +> day_to_int III = 3 +> day_to_int IV = 4 +> day_to_int V = 5 +> day_to_int VI = 6 +> day_to_int VII = 7 +> day_to_int VIII = 8 +> day_to_int IX = 9 +> day_to_int X = 10 +> day_to_int XI = 11 +> day_to_int XII = 12 +> day_to_int XIII = 13 +> day_to_int XIV = 14 +> day_to_int XV = 15 +> day_to_int XVI = 16 +> day_to_int XVII = 17 +> day_to_int XVIII = 18 +> day_to_int XIX = 19 +> day_to_int XX = 20 +> day_to_int XXI = 21 +> day_to_int XXII = 22 +> day_to_int XXIII = 23 +> day_to_int XXIV = 24 +> day_to_int XXV = 25 +> day_to_int XXVI = 26 +> day_to_int XXVII = 27 +> day_to_int XXVIII = 28 +> day_to_int XXIX = 29 +> day_to_int XXX = 30 +> day_to_int XXXI = 31 +> day_to_int _ = 100 + +> month_to_int :: Monat -> Int +> month_to_int Jan = 1 +> month_to_int Feb = 2 +> month_to_int Mar = 3 +> month_to_int Apr = 4 +> month_to_int Mai = 5 +> month_to_int Jun = 6 +> month_to_int Jul = 7 +> month_to_int Aug = 8 +> month_to_int Sep = 9 +> month_to_int Okt = 10 +> month_to_int Nov = 11 +> month_to_int Dez = 12 +> month_to_int _ = 100 + +> int_to_day :: Int -> Tag +> int_to_day 1 = I +> int_to_day 2 = II +> int_to_day 3 = III +> int_to_day 4 = IV +> int_to_day 5 = V +> int_to_day 6 = VI +> int_to_day 7 = VII +> int_to_day 8 = VIII +> int_to_day 9 = IX +> int_to_day 10 = X +> int_to_day 11 = XI +> int_to_day 12 = XII +> int_to_day 13 = XIII +> int_to_day 14 = XIV +> int_to_day 15 = XV +> int_to_day 16 = XVI +> int_to_day 17 = XVII +> int_to_day 18 = XVIII +> int_to_day 19 = XIX +> int_to_day 20 = XX +> int_to_day 21 = XXI +> int_to_day 22 = XXII +> int_to_day 23 = XXIII +> int_to_day 24 = XXIV +> int_to_day 25 = XXV +> int_to_day 26 = XXVI +> int_to_day 27 = XXVII +> int_to_day 28 = XXVIII +> int_to_day 29 = XXIX +> int_to_day 30 = XXX +> int_to_day 31 = XXXI + +> int_to_month :: Int -> Monat +> int_to_month 1 = Jan +> int_to_month 2 = Feb +> int_to_month 3 = Mar +> int_to_month 4 = Apr +> int_to_month 5 = Mai +> int_to_month 6 = Jun +> int_to_month 7 = Jul +> int_to_month 8 = Aug +> int_to_month 9 = Sep +> int_to_month 10 = Okt +> int_to_month 11 = Nov +> int_to_month 12 = Dez + > skonto_to_num :: Skonto -> Float > skonto_to_num s > | s == KeinSkonto = 0 @@ -107,13 +203,13 @@ Helper functions: > | monat d == Feb = > let y = jahr d in > let t = tag d in -> if y `mod` 4 /= 0 && (day_to_str t) > (day_to_str XXVIII) then False +> if y `mod` 4 /= 0 && (day_to_int t) > 28 then False > else > if y `mod` 100 == 0 && y `mod` 400 /= 0 then False > else -> if (day_to_str t) > (day_to_str XXIX) then False +> if (day_to_int t) > 29 then False > else True -> | (day_to_str (tag d)) > (day_to_str XXX) && not(monat d `elem` full_months) = False +> | (day_to_int (tag d)) > 30 && not(monat d `elem` full_months) = False > | otherwise = True > is_payment :: Geschaeftsvorfall -> Bool @@ -128,6 +224,7 @@ Helper functions: > Gutschrift _ _ -> True > _ -> False + Aufgabe A.1 > type P_Geschaeftspartner = Geschaeftspartner @@ -140,9 +237,11 @@ Aufgabe A.1 > } deriving (Eq,Show) > type AP_Kassabucheintrag = (P_Geschaeftspartner,AP_Geschaeftsvorfall) + > waup :: Kassabucheintrag -> AP_Kassabucheintrag > waup (g, v) = eval_payment_sum $ eval_payment_date (g, v) + > eval_payment_date :: Kassabucheintrag -> Kassabucheintrag > eval_payment_date (g, v) > | (is_payment v) && (is_date_valid (zahlung_vom v)) = @@ -159,11 +258,31 @@ Aufgabe A.1 > z = Zahlung (brutto v) (skonto v) (correct_date (zahlung_vom v)) > gs = Gutschrift (gutschriftsbetrag v) (correct_date (gutschrift_vom v)) -> correct_date :: Datum -> Datum -> correct_date d = d > eval_payment_sum :: Kassabucheintrag -> AP_Kassabucheintrag -> eval_payment_sum k = k +> eval_payment_sum (g, v) = (g, correct_sum v) + +> correct_date :: Datum -> Datum +> correct_date d +> | monat d == Feb = +> if y `mod` 4 /= 0 && (day_to_int t) > 28 then fm +> else +> if y `mod` 100 == 0 && y `mod` 400 /= 0 then fm +> else +> if (day_to_int t) > 29 then fm +> else d +> | monat d == Dez && (day_to_int t) > 31 = ny +> | (day_to_int t) > 30 && not(monat d `elem` full_months) = nm +> | otherwise = d +> where +> y = jahr d +> t = tag d +> fm = D (int_to_day 1) Mar y +> nm = D (int_to_day 1) (int_to_month ((month_to_int (monat d)) + 1)) y +> ny = D (int_to_day 1) Jan (y + 1) + +> correct_sum :: Geschaeftsvorfall -> AP_Geschaeftsvorfall +> correct_sum g = g Aufgabe A.2