From 9900764f578e2c3118c24d890f198675cfaaf523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Fri, 31 Mar 2023 19:43:43 +0200 Subject: [PATCH] Prepare fee lookups. --- MODULES.md | 8 ++++++++ member-fees.scm | 37 +++++++++++++++++++++++++++++++++++++ period.scm | 1 + 3 files changed, 46 insertions(+) diff --git a/MODULES.md b/MODULES.md index a189048..e6bd0bc 100644 --- a/MODULES.md +++ b/MODULES.md @@ -219,6 +219,14 @@ Returns the total duration in months of the periods given in the list ```l```. Each period is represented as ```(list start-month end-month)```. + (month-in-periods p [m (*current-month*)]) + +* ```p``` - a periods +* ```m``` - a valid month - defaults to ```(*current-month*)``` + +Returns ```#t``` if given month ```m``` lies within the period +```p```. + (month-in-periods? ps [m (*current-month*)]) * ```ps``` - a list of periods diff --git a/member-fees.scm b/member-fees.scm index 2761421..04905ac 100644 --- a/member-fees.scm +++ b/member-fees.scm @@ -51,6 +51,43 @@ members-base period) + ;; Specifications of fees, regular and student must be in all + (define member-fees-lookup-source + '(((2010 1) #f 500 250))) + + ;; Convert into lookups - a list of (list period regular student) + (define member-fees-lookup-table + (map + (lambda (src) + (let* ((since0 (car src)) + (since (apply make-month since0)) + (before0 (cadr src)) + (before (if before0 + (apply make-month before0) + #f)) + (regular (caddr src)) + (student (cadddr src))) + (list (make-period since before) + regular + student))) + member-fees-lookup-source)) + + ;; Returns a matching list of (list regular student) + (define (lookup-member-fees) + (let loop ((lst member-fees-lookup-table)) + (if (null? lst) + #f + (if (month-in-period? (caar lst)) + (cdar lst) + (loop (cdr lst)))))) + + ;; Returns time-based fee for given type + (define (lookup-member-fee type) + (let ((fees (lookup-member-fees))) + (if (eq? type 'student) + (cadr fees) + (car fees)))) + ;; Returns a list of months where each month is a list containing: ;; * month (from month module) ;; * flags - a list of symbols: student, suspended, destroyed diff --git a/period.scm b/period.scm index aaa8989..5fff4ac 100644 --- a/period.scm +++ b/period.scm @@ -35,6 +35,7 @@ period-bcomment period-markers->periods periods-duration + month-in-period? month-in-periods? periods->string periods-match