-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathExpenseReport.lisp
83 lines (79 loc) · 3.2 KB
/
ExpenseReport.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(defstruct expense
type
amount
)
(defvar NL "
")
(defvar TAB " ")
(defun print-report (htmlMode &rest expenses)
(defvar mealExpenses 0)
(defvar total 0)
(if htmlMode
(progn
(princ (concatenate 'string "<!DOCTYPE html>" NL))
(princ (concatenate 'string "<html lang=\"en\">" NL))
(princ (concatenate 'string "<html>" NL))
(princ (concatenate 'string "<head>" NL))
(princ (concatenate 'string "<title>Expense Report</title>" NL))
(princ (concatenate 'string "</head>" NL))
(princ (concatenate 'string "<body>" NL))
(princ (concatenate 'string "<h1>Expense Report</h1>" NL))
)
(princ (concatenate 'string "Expenses:" NL))
)
(if htmlMode
(progn
(princ (concatenate 'string "<table>" NL))
(princ (concatenate 'string "<thead>" NL))
(princ (concatenate 'string "<tr><th scope=\"col\">Type</th><th scope=\"col\">Amount</th><th scope=\"col\">Over Limit</th></tr>" NL))
(princ (concatenate 'string "</thead>" NL))
(princ (concatenate 'string "<tbody>" NL))
)
)
(loop for expense in expenses do
(if (or (eq (expense-type expense) :dinner) (eq (expense-type expense) :breakfast))
(setq mealExpenses (+ mealExpenses (expense-amount expense))))
(defvar expenseName "")
(case (expense-type expense)
(:dinner (setq expenseName "Dinner"))
(:breakfast (setq expenseName "Breakfast"))
(:car_rental (setq expenseName "Car Rental"))
)
(setq mealOverExpensesMarker (if (or (and (eq (expense-type expense) :dinner) (> (expense-amount expense) 5000)) (and (eq (expense-type expense) :breakfast) (> (expense-amount expense) 1000))) "X" " "))
(if htmlMode
(princ (concatenate 'string "<tr><td>" expenseName "</td><td>" (write-to-string (expense-amount expense)) "</td><td>" mealOverExpensesMarker "</td></tr>" NL))
(princ (concatenate 'string expenseName TAB (write-to-string (expense-amount expense)) TAB mealOverExpensesMarker NL))
)
(setq total (+ total (expense-amount expense)))
)
(if htmlMode
(progn
(princ (concatenate 'string "</tbody>" NL))
(princ (concatenate 'string "</table>" NL))
)
)
(if htmlMode
(progn
(princ (concatenate 'string "<p>Meal Expenses: " (write-to-string mealExpenses) "</p>" NL))
(princ (concatenate 'string "<p>Total Expenses: " (write-to-string total) "</p>" NL))
)
(progn
(princ (concatenate 'string "Meal Expenses: " (write-to-string mealExpenses) NL))
(princ (concatenate 'string "Total Expenses: " (write-to-string total) NL))
)
)
(if htmlMode
(progn
(princ (concatenate 'string "</body>" NL))
(princ (concatenate 'string "</html>" NL))
)
)
)
(print-report
T
(make-expense :type :dinner :amount 5000)
(make-expense :type :dinner :amount 5001)
(make-expense :type :breakfast :amount 1000)
(make-expense :type :breakfast :amount 1001)
(make-expense :type :car_rental :amount 4)
)