-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtransactions.php
More file actions
94 lines (91 loc) · 3.29 KB
/
Copy pathtransactions.php
File metadata and controls
94 lines (91 loc) · 3.29 KB
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
84
85
86
87
88
89
90
91
92
93
94
<?php
include '../app/App.php';
$data = getFile();
$dataLen = count($data);
$totalIncome = getTotals()[0];
$totalExpense = getTotals()[1];
$netTotal = getTotals()[2];
?>
<!DOCTYPE html>
<html>
<head>
<title>Transactions</title>
<style>
table {
width: 100%;
border-collapse: collapse;
text-align: center;
}
table tr th, table tr td {
padding: 5px;
border: 1px #eee solid;
}
tfoot tr th, tfoot tr td {
font-size: 20px;
}
tfoot tr th {
text-align: right;
}
.t-red {
color: red;
}
.t-green {
color: green;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Date</th>
<th>Check #</th>
<th>Description</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<!-- YOUR CODE -->
<?php
for($i = 1; $i<$dataLen; $i++) {
$itemLen = count($data[$i]);
$singleRow = "";
$lastIndex = $itemLen - 1;
for ($j = 0; $j<$itemLen; $j++) {
if ($j === 0) { // check if 1st column and change date format if true
$arrDate = $data[$i][$j];
$arrDate = explode('/', $arrDate);
$setDate = date("M d, Y", mktime(0,0,0,$arrDate[0],$arrDate[1],$arrDate[2]));
$singleRow .= "<td>". $setDate . "</td>";
}
elseif ($j !== $lastIndex) { // check if it's not the last column
$singleRow .= "<td>". $data[$i][$j]."</td>";
} else {
if (str_starts_with($data[$i][$j], '-')) { // check if it's an expense and add red color if true
$singleRow .= "<td class='t-red'>". $data[$i][$j]."</td>";
} else { // check if it's an income and add green color if true
$singleRow .= "<td class='t-green'>". $data[$i][$j]."</td>";
}
}
}
echo "<tr>". $singleRow . "</tr>";
}
?>
</tbody>
<tfoot>
<tr>
<th colspan="3">Total Income:</th>
<?php echo "<td>$". $totalIncome . "</td>"; ?>
</tr>
<tr>
<th colspan="3">Total Expense:</th>
<?php echo "<td>-$". $totalExpense . "</td>"; ?>
</tr>
<tr>
<th colspan="3">Net Total:</th>
<?php echo "<td>$" . $netTotal . "</td>" ?>
</tr>
</tfoot>
</table>
</body>
</html>