Reformatted contract view page
[contractdashboard.git] / graphs / displaySuppliersGraph.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
<?php
include_once ("../lib/common.inc.php");
$topX = 10;
$query = "SELECT value, supplierName
FROM `contractnotice` WHERE (YEAR(contractStart) >= 2009) AND childCN = 0
GROUP BY supplierABN ORDER BY value DESC limit $topX";
$result = mysql_query($query);
$suppliers = Array();
$values = Array();
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
  setlocale(LC_MONETARY, 'en_US');
 // $value = number_format(doubleval($row["value"]) , 2);
  $suppliers[] = ucsmart($row[1]);
  $values[] = doubleval($row["value"]);
}
mysql_free_result($result);
 
$query = "SELECT sum(a.value) as val, supplierCountry from (SELECT value, supplierName, supplierCountry
FROM `contractnotice` WHERE (YEAR(contractStart) >= 2009) AND childCN = 0
GROUP BY supplierName ORDER BY value LIMIT 18446744073709551610 OFFSET $topX) as a group by supplierCountry order by val DESC limit 5 offset 1";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
  $suppliers[] = "Other suppliers in ".ucsmart($row["supplierCountry"]);
  $values[] = doubleval($row[0]);
}
 
mysql_free_result($result);
 
$query = "SELECT sum(a.value) as val, TRUNCATE(supplierPostcode,-2) as postcode from (SELECT value, supplierName, supplierPostcode, supplierCountry
FROM `contractnotice` WHERE (YEAR(contractStart) >= 2009) AND childCN = 0 
GROUP BY supplierName ORDER BY value LIMIT 18446744073709551610 OFFSET $topX) as a
WHERE (supplierCountry LIKE 'Australia' OR supplierCountry LIKE 'AUSTRALIA') AND supplierPostcode < 10000
group by TRUNCATE(supplierPostcode,-2)
order by val DESC";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
    if ($row['postcode'][0] == 2 && $row['postcode'][1] == 6) $ACTvalue += $row[0];
    else if ($row['postcode'][0] == 2 || $row['postcode'][0] == 1) $NSWvalue += $row[0];
    else if ($row['postcode'][0] == 3 || $row['postcode'][0] == 8) $Vicvalue += $row[0];
    else if ($row['postcode'][0] == 4 || $row['postcode'][0] == 9) $QLDvalue += $row[0];
    else if ($row['postcode'][0] == 5) $SAvalue += $row[0];
    else if ($row['postcode'][0] == 6) $WAvalue += $row[0];
    else if ($row['postcode'][0] == 7) $Tasvalue += $row[0];
    else if ($row['postcode'][0] == 0) $NTvalue += $row[0];
}
mysql_free_result($result);
$suppliers[] = "Other suppliers in Australia - ACT";
$values[] = doubleval($ACTvalue);
$suppliers[] = "Other suppliers in Australia - NSW";
$values[] = doubleval($NSWvalue);
$suppliers[] = "Other suppliers in Australia - Victoria";
$values[] = doubleval($Vicvalue);
$suppliers[] = "Other suppliers in Australia - Queensland";
$values[] = doubleval($QLDvalue);
$suppliers[] = "Other suppliers in Australia - NT";
$values[] = doubleval($NTvalue);
$suppliers[] = "Other suppliers in Australia - West Australia";
$values[] = doubleval($WAvalue);
$suppliers[] = "Other suppliers in Australia - South Australia";
$values[] = doubleval($SAvalue);
$suppliers[] = "Other suppliers in Australia - Tasmania";
$values[] = doubleval($Tasvalue);
    
// Width and height of the graph
$width = 800;
$height = 1000;
// Create a graph instance
$graph = new PieGraph($width, $height);
$pieplot = new PiePlot($values);
$pieplot->SetCenter(400, floor($height/2));
$pieplot->SetGuideLines(true, false);
$pieplot->SetLegends($suppliers);
$pieplot->SetTheme('earth');
// Add the plot to the graph
$graph->Add($pieplot);
$graph->legend->SetPos(0.1, 0.97, 'left', 'bottom');
$graph->legend->SetColumns(2);
// Display the graph
$graph->Stroke();
?>