forked from christianhujer/expensereport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExpenseReport.php
42 lines (38 loc) · 1.42 KB
/
ExpenseReport.php
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
<?php
abstract class ExpenseType {
const DINNER = 1;
const BREAKFAST = 2;
const CAR_RENTAL = 3;
}
class Expense {
public $type;
public $amount;
function __construct($type, $amount) {
$this->type = $type;
$this->amount = $amount;
}
}
class ExpenseReport {
function print_report($expenses) {
$mealExpenses = 0;
$total = 0;
$date = date("Y-m-d h:i:sa");
print("Expense Report {$date}\n");
foreach ($expenses as $expense) {
if ($expense->type == ExpenseType::DINNER || $expense->type == ExpenseType::BREAKFAST) {
$mealExpenses += $expense->amount;
}
$expenseName = "";
switch ($expense->type) {
case ExpenseType::DINNER: $expenseName = "Dinner"; break;
case ExpenseType::BREAKFAST: $expenseName = "Breakfast"; break;
case ExpenseType::CAR_RENTAL: $expenseName = "Car Rental"; break;
}
$mealOverExpensesMarker = $expense->type == ExpenseType::DINNER && $expense->amount > 5000 || $expense->type == ExpenseType::BREAKFAST && $expense->amount > 1000 ? "X" : " ";
print($expenseName . "\t" . $expense->amount . "\t" . $mealOverExpensesMarker . "\n");
$total += $expense->amount;
}
print("Meal Expenses: " . $mealExpenses . "\n");
print("Total Expenses: " . $total . "\n");
}
}