Integrate supplier piechart
Integrate supplier piechart

<?php <?php
include_once ("../lib/common.inc.php"); include_once ("../lib/common.inc.php");
$query = 'SELECT c."CNID",c."parentCN",c."amendmentReason",p."childCN" FROM contractnotice as c LEFT OUTER JOIN contractnotice as p on c."parentCN" = p."CNID" $query = 'SELECT c."CNID",c."parentCN",c."amendmentReason",p."childCN" FROM contractnotice as c LEFT OUTER JOIN contractnotice as p on c."parentCN" = p."CNID"
WHERE WHERE
c."parentCN" > 0 AND p."childCN" IS NULL '; c."parentCN" > 0 AND p."childCN" IS NULL ';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} }
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
$conn->exec('UPDATE contractnotice SET "childCN" = \'' . $conn->exec('UPDATE contractnotice SET "childCN" = \'' .
$row['CNID'] . '\', "amendmentReason" = \'' . $row['CNID'] . '\', "amendmentReason" = \'' .
$row['amendmentReason'] . '\' where "CNID" = \'' . $row['amendmentReason'] . '\' where "CNID" = \'' .
$row['parentCN'] . '\';'); $row['parentCN'] . '\';');
echo 'UPDATE contractnotice SET "childCN" = \'' . echo 'UPDATE contractnotice SET "childCN" = \'' .
$row['CNID'] . '\', "amendmentReason" = \'' . $row['CNID'] . '\', "amendmentReason" = \'' .
$row['amendmentReason'] . '\' where "CNID" = \'' . $row['amendmentReason'] . '\' where "CNID" = \'' .
$row['parentCN'] . '\';'; $row['parentCN'] . '\';';
$errors = $conn->errorInfo(); $errors = $conn->errorInfo();
if ($errors[1] == 7 || $errors[1] ==0) if ($errors[1] == 7 || $errors[1] ==0)
echo $row['CNID'] . " linked to parent " . $row['parentCN'] . echo $row['CNID'] . " linked to parent " . $row['parentCN'] .
"<br>\n"; "<br>\n";
else print_r($errors); else print_r($errors);
   
} }
  // also need to eliminate CN 100528/100529 - check for double parent CNs with no childCN, latest sequent CN id wins childCN = 0
?> ?>
<?php <?php
include_once("./lib/common.inc.php"); include_once("./lib/common.inc.php");
include_header("Months and Years"); include_header("Months and Years");
if ($_REQUEST['month']) { if ($_REQUEST['month']) {
echo "<center><h1>".$_REQUEST['month']."</h1></center>"; echo "<center><h1>".$_REQUEST['month']."</h1></center>";
$monthParts = explode("-",$_REQUEST['month']); $monthParts = explode("-",$_REQUEST['month']);
$query = "SELECT CNID, description, value, agencyName, category, contractStart, supplierName $query = 'SELECT "CNID", "description", "value", "agencyName", "category", "contractStart", "supplierName"
FROM `contractnotice` FROM contractnotice
WHERE childCN = 0 WHERE "childCN" = 0
AND YEAR(contractStart) = {$monthParts[1]} AND extract(year from "contractStart") = :year
AND MONTH(contractStart) = {$monthParts[0]} AND extract(month from "contractStart") = :month
ORDER BY value DESC"; ORDER BY value DESC';
$result = mysql_query($query); $query = $conn->prepare($query);
echo '<img src="graphs/displayMethodCountGraph.php?month=' . stripslashes($supplier) . '">'; $query->bindParam(":month", $monthParts[0]);
echo '<img src="graphs/displayCnCGraph.php?month=' . stripslashes($supplier) . '">';  
  $query->bindParam(":year", $monthParts[1]);
  $query->execute();
  if (!$query) {
  databaseError($conn->errorInfo());
  }
   
  MethodCountGraph($supplier);
  CnCGraph($supplier);
echo "<table> <thead> echo "<table> <thead>
<tr> <tr>
<th>Contract Notice Number</th> <th>Contract Notice Number</th>
<th>Contract Description</th> <th>Contract Description</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
<th>Agency</th> <th>Agency</th>
<th>Contract Start Date</th> <th>Contract Start Date</th>
<th>Supplier</th> <th>Supplier</th>
</tr> </tr>
</thead>"; </thead>";
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row['value']) , 2); $value = number_format(doubleval($row['value']) , 2);
echo ("<tr> echo ("<tr>
<td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td> <td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td>
<td><b>{$row['description']}</b></a></td> <td><b>{$row['description']}</b></a></td>
<td>\$$value</td><td>{$row['agencyName']}</td> <td>\$$value</td><td>{$row['agencyName']}</td>
<td>{$row['contractStart']}</td> <td>{$row['contractStart']}</td>
<td>{$row['supplierName']}</td> <td>{$row['supplierName']}</td>
</tr>"); </tr>");
} }
echo "</table>"; echo "</table>";
mysql_free_result($result); mysql_free_result($result);
} else { } else {
/* /*
split by year split by year
todo: todo:
Year/Month drilldown - largest contracts, agencies, suppliers Year/Month drilldown - largest contracts, agencies, suppliers
count per month count per month
big picture graphs?*/ big picture graphs?*/
echo '<img src="graphs/displayContractStartingGraph.php">'; echo '<img src="graphs/displayContractStartingGraph.php">';
echo '<img src="graphs/displayContractPublishedGraph.php">'; echo '<img src="graphs/displayContractPublishedGraph.php">';
$query = "SELECT YEAR(contractStart), MONTH(contractStart), $query = 'SELECT extract(year from "contractStart"), extract(month from "contractStart"),
SUM(value) as val, count(1) as count FROM `contractnotice` WHERE childCN = 0 GROUP BY MONTH(contractStart), YEAR(contractStart) ORDER BY YEAR(contractStart), MONTH(contractStart) "; SUM(value) as val, count(1) as count FROM contractnotice WHERE "childCN" = 0 GROUP BY extract(year from "contractStart"), extract(month from "contractStart") ORDER BY extract(year from "contractStart"), extract(month from "contractStart") ';
  $query = $conn->prepare($query);
  $query->execute();
  if (!$query) {
  databaseError($conn->errorInfo());
  }
$result = mysql_query($query);  
echo "<table> <thead> echo "<table> <thead>
<tr> <tr>
<th>Month/Year</th> <th>Month/Year</th>
<th>Total Contracts Value</th> <th>Total Contracts Value</th>
<th>Number of Contracts</th> <th>Number of Contracts</th>
</tr> </tr>
</thead>"; </thead>";
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row["val"]),2); $value = number_format(doubleval($row["val"]),2);
$month_name = date( 'F', mktime(0, 0, 0, $row[1]) ); $month_name = date( 'F', mktime(0, 0, 0, $row[1]) );
echo ("<tr><td><b><a href=\"?month=$row[1]-$row[0]\">$month_name {$row[0]}</a></b></td><td>\$$value</td><td>({$row['count']} contracts)</td></tr>"); echo ("<tr><td><b><a href=\"?month=$row[1]-$row[0]\">$month_name {$row[0]}</a></b></td><td>\$$value</td><td>({$row['count']} contracts)</td></tr>");
} }
echo "</table>"; echo "</table>";
mysql_free_result($result); mysql_free_result($result);
} }
include_footer(); include_footer();
?> ?>
   
<?php <?php
include('../lib/common.inc.php'); include('lib/common.inc.php');
$year = 2006; $year = 2006;
$ZeroX = 112.5; $ZeroX = 112.5;
$MaxX = 157; $MaxX = 157;
$ZeroY = -9; $ZeroY = -9;
$MaxY = -45; $MaxY = -45;
$XRange = $MaxX - $ZeroX; $XRange = $MaxX - $ZeroX;
$YRange = abs($MaxY) - abs($ZeroY); $YRange = abs($MaxY) - abs($ZeroY);
$xdivs = 250; $xdivs = 250;
$xdivlength = $XRange / $xdivs; $xdivlength = $XRange / $xdivs;
$ydivs = 250; $ydivs = 250;
$ydivheight = $YRange / $ydivs; $ydivheight = $YRange / $ydivs;
$borderLeft = 100; $borderLeft = 100;
$borderTop = 35; $borderTop = 35;
$width = 497; $width = 497;
$height = 457; $height = 457;
//echo "http://dev.openstreetmap.org/~pafciu17/?module=map&bbox=".$ZeroX.",".$ZeroY.",".$MaxX.",".$MaxY."&width=".$width."&height=".$height; //echo "http://dev.openstreetmap.org/~pafciu17/?module=map&bbox=".$ZeroX.",".$ZeroY.",".$MaxX.",".$MaxY."&width=".$width."&height=".$height;
//$handle = ImageCreate ($width, $height) or die ("Cannot Create image"); //$handle = ImageCreate ($width, $height) or die ("Cannot Create image");
$handle = imagecreatefrompng('../images/australia.png'); $handle = imagecreatefrompng('images/australia.png');
$white = imagecolorallocate($handle, 0, 0, 0); $white = imagecolorallocate($handle, 0, 0, 0);
imagecolortransparent($handle, $white); imagecolortransparent($handle, $white);
$query = "SELECT supplierPostcode, sum(value) as value, lat, lon FROM `contractnotice`,`postcodes` where childCN = 0 AND supplierCountry = 'Australia' AND YEAR(contractStart) >= '$year' AND supplierPostcode = postcode GROUP BY supplierPostcode"; $query = 'SELECT "supplierPostcode", sum("value") as value, max(lat) as lat, max(lon) as lon FROM contractnotice inner join postcodes on "supplierPostcode" = postcode::text where "childCN" = 0 AND "supplierCountry" = \'Australia\' GROUP BY "supplierPostcode"';
$result = mysql_query($query); $query = $conn->prepare($query);
  $query->execute();
  if (!$query) {
  databaseError($conn->errorInfo());
  }
   
$left = "FFFF50"; $left = "FFFF50";
$right= "EF0050"; $right= "EF0050";
$leftR = hexdec(substr($left,0,2)); $leftR = hexdec(substr($left,0,2));
$leftG = hexdec(substr($left,2,2)); $leftG = hexdec(substr($left,2,2));
$leftB = hexdec(substr($left,4,2)); $leftB = hexdec(substr($left,4,2));
$rightR = hexdec(substr($right,0,2)); $rightR = hexdec(substr($right,0,2));
$rightG = hexdec(substr($right,2,2)); $rightG = hexdec(substr($right,2,2));
$rightB = hexdec(substr($right,4,2)); $rightB = hexdec(substr($right,4,2));
for($i=0;$i<250;$i++) { for($i=0;$i<250;$i++) {
$colorset[$i] = imagecolorallocatealpha($handle, $leftR + ($i*(($rightR-$leftR)/250)), $leftG + ($i*(($rightG-$leftG)/250)), $leftB + ($i*(($rightB-$leftB)/250)),117 - ($i/250)*40); $colorset[$i] = imagecolorallocatealpha($handle, $leftR + ($i*(($rightR-$leftR)/250)), $leftG + ($i*(($rightG-$leftG)/250)), $leftB + ($i*(($rightB-$leftB)/250)),117 - ($i/250)*40);
} }
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) foreach ($query->fetchAll() as $row) {
{  
$xpage = round((($XRange - ($MaxX - $row['lon'])) / $xdivlength)); $xpage = round((($XRange - ($MaxX - $row['lon'])) / $xdivlength));
if ($row['lat'] < -40.25) $row['lat']-= 0.75; if ($row['lat'] < -40.25) $row['lat']-= 0.75;
$ypage = round(($YRange - (abs($MaxY) - abs($row['lat']))) / $ydivheight); $ypage = round(($YRange - (abs($MaxY) - abs($row['lat']))) / $ydivheight);
@$pagevalues[$xpage][$ypage] += $row['value']; @$pagevalues[$xpage][$ypage] += $row['value'];
//echo $ypage." ".$xpage."<br>"; //echo $ypage." ".$xpage."<br>";
} }
$max = 0; $max = 0;
$min = 0; $min = 0;
for ($i = 0;$i < $xdivs; $i++ ) { for ($i = 0;$i < $xdivs; $i++ ) {
for ($j = 0;$j < $ydivs; $j++ ) { for ($j = 0;$j < $ydivs; $j++ ) {
if (@$pagevalues[$i][$j]) if (@$pagevalues[$i][$j])
{ {
if (@$pagevalues[$i][$j] > $max) $max = @$pagevalues[$i][$j]; if (@$pagevalues[$i][$j] > $max) $max = @$pagevalues[$i][$j];
if ($min == 0 || @$pagevalues[$i][$j] < $min) $min = @$pagevalues[$i][$j]; if ($min == 0 || @$pagevalues[$i][$j] < $min) $min = @$pagevalues[$i][$j];
} else { } else {
@$pagevalues[$i][$j] = ((@$pagevalues[$i][$j] + (@$pagevalues[$i+1][$j] + @$pagevalues[$i][$j+1] @$pagevalues[$i][$j] = ((@$pagevalues[$i][$j] + (@$pagevalues[$i+1][$j] + @$pagevalues[$i][$j+1]
+ @$pagevalues[$i-1][$j] + @$pagevalues[$i][$j-1])/4) /2)-9; + @$pagevalues[$i-1][$j] + @$pagevalues[$i][$j-1])/4) /2)-9;
@$pagevalues[$i-1][$j] = ((@$pagevalues[$i-1][$j] + (@$pagevalues[$i][$j] + @$pagevalues[$i-1][$j+1] @$pagevalues[$i-1][$j] = ((@$pagevalues[$i-1][$j] + (@$pagevalues[$i][$j] + @$pagevalues[$i-1][$j+1]
+ @$pagevalues[$i-2][$j] + @$pagevalues[$i-1][$j-1])/4) /2)-9; + @$pagevalues[$i-2][$j] + @$pagevalues[$i-1][$j-1])/4) /2)-9;
@$pagevalues[$i][$j-1] = ((@$pagevalues[$i][$j-1] + (@$pagevalues[$i+1][$j-1] + @$pagevalues[$i][$j] @$pagevalues[$i][$j-1] = ((@$pagevalues[$i][$j-1] + (@$pagevalues[$i+1][$j-1] + @$pagevalues[$i][$j]
+ @$pagevalues[$i-1][$j-1] + @$pagevalues[$i][$j-2])/4) /2)-9; + @$pagevalues[$i-1][$j-1] + @$pagevalues[$i][$j-2])/4) /2)-9;
} }
} }
} }
//echo $max." ".$min; //echo $max." ".$min;
//echo "<table width='100%'>"; //echo "<table width='100%'>";
for ($i = 0;$i < $xdivs; $i++ ) { for ($i = 0;$i < $xdivs; $i++ ) {
// echo "<tr>"; // echo "<tr>";
for ($j = 0; $j < $ydivs; $j++ ) { for ($j = 0; $j < $ydivs; $j++ ) {
// echo ("<td>". log10(@$pagevalues[$i][$j])/log10($max) ."</td>"); // echo ("<td>". log10(@$pagevalues[$i][$j])/log10($max) ."</td>");
if ((@$pagevalues[$i][$j]) > $min) { if ((@$pagevalues[$i][$j]) > $min) {
$x = $i*($width/$xdivs); $x = $i*($width/$xdivs);
$x1 = $borderLeft + $x -($width/$xdivs); $x1 = $borderLeft + $x -($width/$xdivs);
$x2 = $borderLeft + $x +($width/$xdivs); $x2 = $borderLeft + $x +($width/$xdivs);
$y = $j*($height/$ydivs); $y = $j*($height/$ydivs);
$y1 = $borderTop + $y - ($height/$ydivs); $y1 = $borderTop + $y - ($height/$ydivs);
$y2 = $borderTop + $y + ($height/$ydivs); $y2 = $borderTop + $y + ($height/$ydivs);
imagefilledrectangle ($handle, $x1, $y1, $x2, $y2, $colorset[(int)((log10(@$pagevalues[$i][$j])/log10($max))*249)]); imagefilledrectangle ($handle, $x1, $y1, $x2, $y2, $colorset[(int)((log10(@$pagevalues[$i][$j])/log10($max))*249)]);
} }
} }
//echo "</tr>"; //echo "</tr>";
} }
//echo "</table>" //echo "</table>"
header ("Content-type: image/png"); header ("Content-type: image/png");
ImagePng ($handle); ImagePng ($handle);
?> ?>
<?php <?php
include_once ("./lib/common.inc.php"); include_once ("./lib/common.inc.php");
if ($_REQUEST['supplier']) { if ($_REQUEST['supplier']) {
include_header("Supplier"); include_header("Supplier");
$supplierS = htmlentities(strip_tags($_REQUEST['supplier'])); $supplierS = htmlentities(strip_tags($_REQUEST['supplier']));
echo '<img src="graphs/displayMethodCountGraph.php?supplier=' . stripslashes($supplierS) . '">'; MethodCountGraph($supplierS);
echo '<img src="graphs/displayCnCGraph.php?supplier=' . stripslashes($supplierS) . '">'; CnCGraph($supplierS);
echo '<img src="graphs/displayMethodValueGraph.php?supplier=' . stripslashes($supplierS) . '">'; MethodValueGraph($supplierS);
/*lobbyist ties /*lobbyist ties
links to ABR/ASIC/Google News/ASX/Court records links to ABR/ASIC/Google News/ASX/Court records
total value to various agencies (bar graph) total value to various agencies (bar graph)
spread procurement methods + percent consultancies + percent confidential (bar graph) spread procurement methods + percent consultancies + percent confidential (bar graph)
spread of contract values spread of contract values
spread of industries (textual?)*/ spread of industries (textual?)*/
$query = 'SELECT "CNID", "description", "value", "agencyName", "category", $query = 'SELECT "CNID", "description", "value", "agencyName", "category",
"contractStart", "supplierName" "contractStart", "supplierName"
FROM contractnotice WHERE '. FROM contractnotice WHERE '.
$supplierQ.' '.$standardQ $supplierQ.' '.$standardQ
.' ORDER BY value DESC'; .' ORDER BY value DESC';
echo $query; echo $query;
$query = $conn->prepare($query); $query = $conn->prepare($query);
   
//$query->bindParam(":supplierName", $supplierName); //$query->bindParam(":supplierName", $supplierName);
$query->bindParam(":supplierABN", $supplierABN); $query->bindParam(":supplierABN", $supplierABN);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} }
echo '<img src="graphs/displayMethodCountGraph.php?month=' . stripslashes($supplier) . '">'; echo '<img src="graphs/displayMethodCountGraph.php?month=' . stripslashes($supplier) . '">';
echo '<img src="graphs/displayCnCGraph.php?month=' . stripslashes($supplier) . '">'; echo '<img src="graphs/displayCnCGraph.php?month=' . stripslashes($supplier) . '">';
   
echo "<table> <thead> echo "<table> <thead>
<tr> <tr>
<th>Contract Notice Number</th> <th>Contract Notice Number</th>
<th>Contract Description</th> <th>Contract Description</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
<th>Agency</th> <th>Agency</th>
<th>Contract Start Date</th> <th>Contract Start Date</th>
<th>Supplier</th> <th>Supplier</th>
</tr> </tr>
</thead>"; </thead>";
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row['value']) , 2); $value = number_format(doubleval($row['value']) , 2);
echo ("<tr> echo ("<tr>
<td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td> <td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td>
<td><b>{$row['description']}</b></a></td> <td><b>{$row['description']}</b></a></td>
<td>\$$value</td><td>{$row['agencyName']}</td> <td>\$$value</td><td>{$row['agencyName']}</td>
<td>{$row['contractStart']}</td> <td>{$row['contractStart']}</td>
<td>{$row['supplierName']}</td> <td>{$row['supplierName']}</td>
</tr>"); </tr>");
} }
echo "</table>"; echo "</table>";
} else { } else {
/* /*
histograph of supplier size/value histograph of supplier size/value
*/ */
include_header("Suppliers"); include_header("Suppliers");
  suppliersGraph();
$query = 'SELECT SUM("value") as val, MAX("supplierName") as supplierName, "supplierABN",( $query = 'SELECT SUM("value") as val, MAX("supplierName") as supplierName, "supplierABN",(
case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID
FROM contractnotice FROM contractnotice
WHERE "childCN" = 0 WHERE "childCN" = 0
GROUP BY supplierID,"supplierABN" GROUP BY supplierID,"supplierABN"
ORDER BY val DESC ORDER BY val DESC
LIMIT 100'; LIMIT 100';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} }
echo "<table> <thead> echo "<table> <thead>
<tr> <tr>
<th>Position</th> <th>Position</th>
<th>Supplier</th> <th>Supplier</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
</tr> </tr>
</thead>"; </thead>";
$i = 1; $i = 1;
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row['val']) , 2); $value = number_format(doubleval($row['val']) , 2);
$supplier = stripslashes($row['supplierABN'].'-'.$row['suppliername']); $supplier = stripslashes($row['supplierABN'].'-'.$row['suppliername']);
echo ("<tr><td>$i</td><td><b><a href=\"displaySupplier.php?supplier={$supplier}\">".ucsmart($row['suppliername'])."</a></b></td><td>\$$value</td></tr>\n"); echo ("<tr><td>$i</td><td><b><a href=\"displaySupplier.php?supplier={$supplier}\">".ucsmart($row['suppliername'])."</a></b></td><td>\$$value</td></tr>\n");
$i++; $i++;
} }
echo "</table>"; echo "</table>";
} }
include_footer(); include_footer();