<?php | <?php |
include_once ("./lib/common.inc.php"); | include_once ("./lib/common.inc.php"); |
if ($_REQUEST['agency']) { | if ($_REQUEST['agency']) { |
$agency = htmlentities(strip_tags($_REQUEST['agency'])); | $agency = htmlentities(strip_tags($_REQUEST['agency'])); |
include_header($agency); | include_header($agency); |
echo '<center><h1>'.$agency.'</h1></center>'; | echo '<center><h1>'.$agency.'</h1></center>'; |
agencySuppliersGraph($agency); | agencySuppliersGraph($agency); |
// MethodCountGraph($agency); | /* |
// CnCGraph($agency); | * * Common categories and uncommon categories |
// MethodValueGraph($agency); | * Procurement method in text, seperate Open via SON from Open |
/* biggest contracts | * Consultancies, Confidentialities percentage |
spending by year | |
spending by industry/category | |
spending by supplier | |
spread procurement methods (stacked bar graph) | |
+ percent consultancies + percent confidential (bar graph) | |
Average value by procurement type | |
--- info | |
website, procurement plan, annual reports | |
Breakdown of divisions/branches | |
Breakdown percentage,number,value by procurement type | |
Histograph, overlaying number value reported per week over X years | |
Compliance statistics: amendments, delay in reporting average and number completely late */ | Compliance statistics: amendments, delay in reporting average and number completely late */ |
$query = 'SELECT "CNID", "description", "value", "agencyName", "category", | $query = 'SELECT "CNID", "description", "value", "agencyName", "category", |
"contractStart", "supplierName" | "contractStart", "supplierName" |
FROM contractnotice | FROM contractnotice |
WHERE ' .$yearQ . ' "agencyName" like :agency and "childCN" is null | WHERE ' .$yearQ . ' "agencyName" like :agency and "childCN" is null |
ORDER BY "value" DESC limit 100'; | ORDER BY "value" DESC limit 100'; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":agency", $agency); | $query->bindParam(":agency", $agency); |
$query->execute(); | $query->execute(); |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
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 { |
/* | /* |
split by portfolio | split by portfolio |
*/ | */ |
include_header("Agencies"); | include_header("Agencies"); |
agenciesGraph(); | agenciesGraph(); |
$query = 'SELECT SUM("value"), "agencyName" | $query = 'SELECT SUM("value"), "agencyName" |
FROM contractnotice | FROM contractnotice |
WHERE ' .$yearQ . ' "childCN" is null | WHERE ' .$yearQ . ' "childCN" is null |
GROUP BY "agencyName" '; | GROUP BY "agencyName" '; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->execute(); | $query->execute(); |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
echo "<table> <thead> | echo "<table> <thead> |
<tr> | <tr> |
<th>Agency</th> | <th>Agency</th> |
<th>Total Contracts Value</th> | <th>Total Contracts Value</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[0]), 2); | $value = number_format(doubleval($row[0]), 2); |
$agency = stripslashes($row[1]); | $agency = stripslashes($row[1]); |
echo ("<tr><td><b><a href=\"displayAgency.php?agency={$agency}\">{$agency}</a></b></td><td>\$$value</td></tr>\n"); | echo ("<tr><td><b><a href=\"displayAgency.php?agency={$agency}\">{$agency}</a></b></td><td>\$$value</td></tr>\n"); |
} | } |
echo "</table>"; | echo "</table>"; |
} | } |
include_footer(); | include_footer(); |
?> | ?> |
<?php | <?php |
include_once ("./lib/common.inc.php"); | include_once ("./lib/common.inc.php"); |
if ($_REQUEST['supplier']) { | if ($_REQUEST['supplier']) { |
$supplierS = htmlentities(strip_tags($_REQUEST['supplier'])); | $supplierS = htmlentities(strip_tags($_REQUEST['supplier'])); |
include_header(str_replace("%","",$supplierName)); | $title = $supplierName; |
echo '<center><h1>'.str_replace("%","",$supplierName).'</h1></center>'; | if ($supplierABN) { |
$query = 'SELECT text_mode("supplierName") as "supplierName" from contractnotice where "supplierABN" = :supplierABN group by "supplierABN"'; | |
$query = $conn->prepare($query); | |
$query->bindParam(":supplierABN", $supplierABN); | |
$query->execute(); | |
databaseError($conn->errorInfo()); | |
$title = reset($query->fetchAll())['supplierName']; | |
} | |
include_header(str_replace("%","",$title)); | |
echo '<center><h1>'.str_replace("%","",$title).'</h1></center>'; | |
agenciesGraph(); | agenciesGraph(); |
// MethodCountGraph($supplierS); | /* |
// CnCGraph($supplierS); | * Make supplier name the most common name for this ABN |
// MethodValueGraph($supplierS); | * Common names and uncommon names |
/* lobbyist ties | * Common categories and uncommon categories |
* Procurement method in text, seperate Open via SON from Open | |
links to ABR/ASIC/Google News/ASX/Court records | * Consultancies, Confidentialities percentage |
*/ | |
total value to various agencies (bar graph) | |
spread procurement methods + percent consultancies + percent confidential (bar graph) | |
spread of contract values | |
spread of industries (textual?) */ | |
// echo '<img src="graphs/displayMethodCountGraph.php?month=' . stripslashes($supplier) . '">'; | |
// echo '<img src="graphs/displayCnCGraph.php?month=' . stripslashes($supplier) . '">'; | |
$query = 'select contractnotice."SONID", min(title) as title, count(*), sum(value) as value from contractnotice inner join standingoffers on contractnotice."SONID" = standingoffers."SONID" WHERE ' .$yearQ . ' ' . | $query = 'select contractnotice."SONID", min(title) as title, count(*), sum(value) as value from contractnotice inner join standingoffers on contractnotice."SONID" = standingoffers."SONID" WHERE ' .$yearQ . ' ' . |
$supplierQ . ' ' . $standardQ | $supplierQ . ' ' . $standardQ |
. ' and contractnotice."SONID" != \'\' group by contractnotice."SONID"'; | . ' and contractnotice."SONID" != \'\' group by contractnotice."SONID"'; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
if ($supplierParts[0] > 0) { | if ($supplierParts[0] > 0) { |
$query->bindParam(":supplierABN", $supplierABN); | $query->bindParam(":supplierABN", $supplierABN); |
} else { | } else { |
$query->bindParam(":supplierName", $supplierName); | $query->bindParam(":supplierName", $supplierName); |
} | } |
$query->execute(); | $query->execute(); |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
echo "<table> <thead> | echo "<h3>Standing Offers/Panels</h3><table> <thead> |
<tr> | <tr> |
<th>Standing Offer</th> | <th>Standing Offer</th> |
<th>Contracts Count</th> | <th>Contracts Count</th> |
<th>Total Contract Value</th> | <th>Total Contract Value</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><B><a href=\"displaySON.php?SONID={$row['SONID']}\">{$row['title']}</a></b></td> | <td><B><a href=\"displaySON.php?SONID={$row['SONID']}\">{$row['title']}</a></b></td> |
<td>{$row['count']}</td> | <td>{$row['count']}</td> |
<td>\$$value</td> | <td>\$$value</td> |
</tr>"); | </tr>"); |
} | } |
echo "</table><table> <thead> | echo "</table><table><h3>Contracts</h3> <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>"; |
$query = 'SELECT "CNID", "description", "value", "agencyName", "category", | $query = 'SELECT "CNID", "description", "value", "agencyName", "category", |
"contractStart", "supplierName" | "contractStart", "supplierName" |
FROM contractnotice WHERE ' .$yearQ . ' ' . | FROM contractnotice WHERE ' .$yearQ . ' ' . |
$supplierQ . ' ' . $standardQ | $supplierQ . ' ' . $standardQ |
. ' ORDER BY value DESC'; | . ' ORDER BY value DESC'; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
if ($supplierParts[0] > 0) { | if ($supplierParts[0] > 0) { |
$query->bindParam(":supplierABN", $supplierABN); | $query->bindParam(":supplierABN", $supplierABN); |
} else { | } else { |
$query->bindParam(":supplierName", $supplierName); | $query->bindParam(":supplierName", $supplierName); |
} | } |
$query->execute(); | $query->execute(); |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
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(); | suppliersGraph(); |
$query = 'SELECT SUM("value") as val, mode("supplierName") as supplierName, "supplierABN",( | $query = 'SELECT SUM("value") as val, text_mode("supplierName") as supplierName, "supplierABN",( |
case when "supplierABN" != 0 THEN lower("supplierABN"::text) ELSE lower("supplierName") END) as supplierID | case when "supplierABN" != 0 THEN lower("supplierABN"::text) ELSE lower("supplierName") END) as supplierID |
FROM contractnotice | FROM contractnotice |
WHERE ' .$yearQ . ' "childCN" is null | WHERE ' .$yearQ . ' "childCN" is null |
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(); |
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(); |
?> | ?> |
-- https://wiki.postgresql.org/wiki/Aggregate_Mode | -- https://wiki.postgresql.org/wiki/Aggregate_Mode |
CREATE OR REPLACE FUNCTION _final_mode(anyarray) | CREATE OR REPLACE FUNCTION _final_mode(anyarray) |
RETURNS anyelement AS | RETURNS anyelement AS |
$BODY$ | $BODY$ |
SELECT a | SELECT a |
FROM unnest($1) a | FROM unnest($1) a |
GROUP BY 1 | GROUP BY 1 |
ORDER BY COUNT(1) DESC, 1 | ORDER BY COUNT(1) DESC, 1 |
LIMIT 1; | LIMIT 1; |
$BODY$ | $BODY$ |
LANGUAGE 'sql' IMMUTABLE; | LANGUAGE 'sql' IMMUTABLE; |
-- Tell Postgres how to use our aggregate | -- Tell Postgres how to use our aggregate |
CREATE AGGREGATE mode(anyelement) ( | CREATE AGGREGATE text_mode(anyelement) ( |
SFUNC=array_append, --Function to call for each row. Just builds the array | SFUNC=array_append, --Function to call for each row. Just builds the array |
STYPE=anyarray, | STYPE=anyarray, |
FINALFUNC=_final_mode, --Function to call after everything has been added to array | FINALFUNC=_final_mode, --Function to call after everything has been added to array |
INITCOND='{}' --Initialize an empty array when starting | INITCOND='{}' --Initialize an empty array when starting |
); | ); |
CREATE VIEW suppliers AS | |
select distinct on ("supplierABN") "supplierABN", "supplierName", count("supplierName") from contractnotice | |
where "supplierABN" is not null | |
group by "supplierABN", "supplierName" | |
order by "supplierABN" asc, count("supplierName") desc; |
<?php | <?php |
$includedFlot = false; | $includedFlot = false; |
function includeFlot() { | function includeFlot() { |
if (!$includedFlot) { | if (!$includedFlot) { |
echo ' <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="lib/flot/excanvas.min.js"></script><![endif]--> | echo ' <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="lib/flot/excanvas.min.js"></script><![endif]--> |
<script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.js"></script> | <script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.js"></script> |
<script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.pie.js"></script> | <script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.pie.js"></script> |
<script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.selection.js"></script> | <script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.selection.js"></script> |
<script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.stack.js"></script> | <script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.stack.js"></script> |
'; | '; |
$includedFlot = true; | $includedFlot = true; |
} | } |
} | } |
function CNDistributionGraph() { | function CNDistributionGraph() { |
global $conn; | global $conn; |
includeFlot(); | includeFlot(); |
?> | ?> |
<center><div id="cndist" style="width:900px;height:550px"></div></center> | <center><div id="cndist" style="width:900px;height:550px"></div></center> |
<script type="text/javascript"> | <script type="text/javascript"> |
var placeholder = $("#cndist"); | var placeholder = $("#cndist"); |
$(function () { | $(function () { |
var d1 = []; | var d1 = []; |
var d2 = []; | var d2 = []; |
<?php | <?php |
$query = 'select cnid, count(*) from | $query = 'select cnid, count(*) from |
(select ("CNID"::integer - MOD("CNID"::integer,100)) as cnid | (select ("CNID"::integer - MOD("CNID"::integer,100)) as cnid |
from contractnotice where "CNID"::integer < 999999 | from contractnotice where "CNID"::integer < 999999 |
and "CNID" not like \'%-A%\' | and "CNID" not like \'%-A%\' |
and "parentCN" is null) as a group by cnid order by cnid'; | and "parentCN" is null) as a group by cnid order by cnid'; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->execute(); | $query->execute(); |
$errors = $conn->errorInfo(); | $errors = $conn->errorInfo(); |
if ($errors[2] != "") { | if ($errors[2] != "") { |
echo("Export terminated, db error" . print_r($errors, true)); | echo("Export terminated, db error" . print_r($errors, true)); |
return Array(); | return Array(); |
} | } |
foreach ($query->fetchAll() as $delta) { | foreach ($query->fetchAll() as $delta) { |
echo "d1.push([ " . intval($delta['cnid']) . ", " . intval($delta['count']) . "]); \n"; | echo "d1.push([ " . intval($delta['cnid']) . ", " . intval($delta['count']) . "]); \n"; |
}; | }; |
$query = 'select cnid, count(*) from (select ("CNID"::integer - MOD("CNID"::integer,100)) as cnid | $query = 'select cnid, count(*) from (select ("CNID"::integer - MOD("CNID"::integer,100)) as cnid |
from contractnotice where "CNID" not like \'%-A%\' and "parentCN" is not null) | from contractnotice where "CNID" not like \'%-A%\' and "parentCN" is not null) |
as a group by cnid order by cnid'; | as a group by cnid order by cnid'; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->execute(); | $query->execute(); |
$errors = $conn->errorInfo(); | $errors = $conn->errorInfo(); |
if ($errors[2] != "") { | if ($errors[2] != "") { |
echo("Export terminated, db error" . print_r($errors, true)); | echo("Export terminated, db error" . print_r($errors, true)); |
return Array(); | return Array(); |
} | } |
foreach ($query->fetchAll() as $delta) { | foreach ($query->fetchAll() as $delta) { |
echo "d2.push([ " . intval($delta['cnid']) . ", " . intval($delta['count']) . "]); \n"; | echo "d2.push([ " . intval($delta['cnid']) . ", " . intval($delta['count']) . "] |