-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplates-projects-over-budget.php
164 lines (128 loc) · 3.7 KB
/
templates-projects-over-budget.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
/**
* Template Name: Projects over budget
*/
get_header(); ?>
<style>
.attention {
color: red;
font-weight: bold;
}
</style>
<?php
// Function for sorting array
function aasort(&$array, $key) {
$sorter = array();
$ret = array();
reset($array);
foreach($array as $ii => $va) {
$sorter[$ii] = $va[$key];
}
asort($sorter);
foreach($sorter as $ii => $va) {
$ret[$ii] = $array[$ii];
}
$array=$ret;
}
// Get results
global $wpdb;
$results = $wpdb->get_results('
SELECT
orbis_companies.name AS company_name,
orbis_projects.name,
orbis_projects.id,
orbis_projects.number_seconds AS project_time,
SUM(orbis_hours_registration.number_seconds) AS registration_time,
orbis_projects.post_id
FROM
orbis_projects
LEFT JOIN
orbis_hours_registration
ON(orbis_hours_registration.project_id = orbis_projects.id)
LEFT JOIN
orbis_companies
ON(orbis_projects.principal_id = orbis_companies.id)
WHERE finished = 0 && invoicable = 1
GROUP BY orbis_projects.id
');
// New array
$projects = array();
foreach ( $results as $row ) : if ( $row->registration_time > $row->project_time ) :
$projects[$row->id]['company_name'] = $row->company_name;
$projects[$row->id]['name'] = $row->name;
$projects[$row->id]['post_id'] = $row->post_id;
$projects[$row->id]['registration_time'] = $row->registration_time;
$projects[$row->id]['project_time'] = $row->project_time;
$projects[$row->id]['over_budget'] = $row->registration_time / $row->project_time * 100;
$projects[$row->id]['hours_over_budget'] = $row->registration_time - $row->project_time;
endif; endforeach;
?>
<div class="row">
<div class="col-md-6">
<?php
aasort( $projects, 'over_budget' );
$projects = array_reverse( $projects, true );
?>
<h2>Grootste overschrijding</h2>
<div class="panel">
<table class="table table-striped table-bordered table-condense">
<thead>
<tr>
<th><?php _e( 'Project', 'orbis_pronamic' ); ?></th>
<th><?php _e( 'Over budget', 'orbis_pronamic' ); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ( $projects as $project ) : ?>
<tr>
<td>
<a href="<?php echo get_permalink( $project['post_id'] ); ?>">
<?php echo $project['company_name']; ?> - <?php echo $project['name']; ?>
</a>
</td>
<td <?php if($project['over_budget'] > 150) { echo 'class="attention"'; } ?>><?php echo round($project['over_budget']); ?>%</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<div class="col-md-6">
<?php
aasort( $projects, 'hours_over_budget' );
$projects = array_reverse($projects, true);
?>
<h2>Grootste verlies</h2>
<div class="panel">
<table class="table table-striped table-bordered table-condense">
<thead>
<tr>
<th><?php _e( 'Project', 'orbis_pronamic' ); ?></th>
<th><?php _e( 'Aantal uren over budget', 'orbis_pronamic' ); ?></th>
<th><?php _e( 'Kosten', 'orbis_pronamic' ); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($projects as $project ) : ?>
<?php
$total = $project['hours_over_budget'];
$total = $total / 60 / 60;
$total = round($total);
$amount = $total * 75;
?>
<tr>
<td>
<a href="<?php echo get_permalink( $project['post_id'] ); ?>">
<?php echo $project['company_name']; ?> - <?php echo $project['name']; ?>
</a>
</td>
<td><?php echo $total; ?> uren</td>
<td <?php if($total > 10) { echo 'class="attention"'; } ?>>€ <?php echo number_format( $amount, 2, ',', '.' ); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php get_footer(); ?>