-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceipt.php
78 lines (68 loc) · 2.46 KB
/
receipt.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
function __autoload($class_name) {
include $class_name . '.php';
}
function get_total($a, $x) {
$len = count($a) - 1;
$prod_str = '';
$prod_str .= "<tr><td colspan='5' align='right'><b>Subtotal:</b> ".$a[$len-3][$x+1]."</td></tr>";
$prod_str .= "<tr><td colspan='5' align='right'><b>10% Mark Up:</b> ".$a[$len-2][$x+1]."</td></tr>";
$prod_str .= "<tr><td colspan='5' align='right'><b>Credits:</b> ".$a[$len-1][$x+1]."</td></tr>";
$prod_str .= "<tr><td colspan='5' align='right'><b>Total:</b> ".$a[$len][$x+1]."</td></tr>";
return $prod_str;
}
function get_products($a, $x) {
$len = count($a) - 2;
$prod_str = '';
for($y = 1; $y < $len; $y += 1) {
$klass = '';
if ($a[$y][$x] != 0){
if (($a[$y][1] != $a[$y][2]) && is_numeric($a[$y][1])){
$klass = " class='unfilled'";
}
$prod_str .= "<tr$klass><td valign='top' style='width:10px;'>".$a[$y][$x]."</td><td valign='top'>".Helpers::scrubber($a[$y][3])."</td><td style='width:290px;'>".Helpers::scrubber($a[$y][0])."</td><td>".$a[$y][4]."</td><td align='right'>".$a[$y][$x+1]."</td></tr>\n";
}
}
return $prod_str;
}
function receipt() {
$order_array = array();
if (!file_exists(Config::DATAFILE)) {
echo 'ERROR: Data file does not exist';
return;
};
$handle = fopen(Config::DATAFILE, "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
array_push($order_array, $data);
}
fclose($handle);
$len = sizeof($order_array[0]) - 2;
for ($x = 6; $x < $len; $x += 1) {
if ($order_array[0][$x] != '') {
$name = Helpers::scrubber($order_array[0][$x]);
$products = get_products($order_array, $x);
if ($products != '') {
echo "<a name='".$name."'/>";
echo $name."<br/>";
echo "<table>";
echo "<tr><th colspan='3' style='width:300px;'>Amount of Product</th><th>Price</th><th>Order Price</th></tr>\n";
echo $products;
echo get_total($order_array, $x);
echo "</table>\n<p/><hr align='left' width='600'><p/>";
}
}
}
}
?>
<html>
<head>
<title>Food Buying Club</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<a href="./">« back to main</a><p/>
<?
receipt();
?>
</body>
</html>