-
Notifications
You must be signed in to change notification settings - Fork 1
/
stdlib.php
55 lines (49 loc) · 1.04 KB
/
stdlib.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
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
$months = array(
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
);
function sumTransactions($data) {
$total = 0.0;
foreach ($data as $datum) {
$total += $datum['amount'];
}
if ($total < 0) {
return "($" . number_format($total,2) . ")";
}
return "$" . number_format($total,2);
}
function totalTransactions($income, $expenses) {
$total = 0.0;
foreach ($income as $datum) {
$total += $datum['amount'];
}
foreach ($expenses as $datum) {
$total -= $datum['amount'];
}
if ($total < 0) {
return "($" . number_format($total,2) . ")";
}
return "$" . number_format($total,2);
}
function calculateMargin($income, $expenses) {
$revenue = 0.0;
foreach ($income as $datum) {
$revenue += $datum['amount'];
}
$cost = 0.0;
foreach ($expenses as $datum) {
$cost += $datum['amount'];
}
return number_format((1 - ($cost/$revenue)) * 100, 2) . "%";
}