-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.php
100 lines (88 loc) · 2.71 KB
/
report.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
require_once 'header.php';
$userId = getCurrentUserId();
$query = <<<STR
select name
, p.projectId
, pl.laborCost
, pm.materialCost
, pm.numMaterials
, pl.numTasks
from project p
left join (select projectId, count(projectLaborItemId) numTasks, sum(CostPerHour * Hours) as laborCost from projectLaborItem group by projectId) pl on p.projectId = pl.projectId
left join (select projectId, count(materialId) numMaterials, sum(cost * number) as materialCost from projectMaterial group by projectId) pm on p.projectId = pm.projectId
where p.id = $userId
order by lower(p.name)
STR;
$projects = executeQuery($query);
?>
<h4><br>User Projects Report</h4>
<table class='report'>
<thead>
<tr>
<th>Project Name</th>
<th>Material Types</th>
<th>Material Cost</th>
<th>Qty. Tasks</th>
<th>Labor Cost</th>
<th>Total Cost</th>
</tr>
<thead>
<tbody>
<?php
$numberOfProjects = 0;
foreach ($projects as $project)
{
extract($project);
$totalCostOfProjects += $materialCost + $laborCost;
$projectCost = money_format($materialCost + $laborCost);
$laborCost = money_format($laborCost);
$materialCost = money_format($materialCost);
$numberOfProjects++;
$output .= <<<ABC
<tr>
<td>$name</td>
<td class="numberColumn">$numMaterials</td>
<td class="numberColumn">$materialCost</td>
<td class="numberColumn">$numTasks</td>
<td class="numberColumn">$laborCost</td>
<td class="numberColumn">$projectCost</td>
</tr>
ABC;
}
echo($output);
?>
<tbody>
<tfoot>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td style="border-top: solid 2px black !important;">Total:</td>
<td style="border-top: solid 2px black !important;"><?php echo money_format($totalCostOfProjects) ?></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>Num. Projects:</td>
<td><?php echo $numberOfProjects ?></td>
</tr>
<?php if($numberOfProjects != 0) {?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>Avg. Project Cost:</td>
<td><?php echo money_format($totalCostOfProjects/$numberOfProjects) ?></td>
</tr>
<?php } ?>
</tfoot>
</table>
<div class="contentClear"><p>Return to the <a href="home.php">Projects Page</a></p></div>
<?php
require_once 'footer.php';
?>