more panel/category tables
more panel/category tables

<?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); $query = 'SELECT category, min("categoryUNSPSC") AS "categoryUNSPSC", count(*) AS count, sum(value) AS value FROM contractnotice
// MethodCountGraph($agency); WHERE "agencyName" LIKE :agency AND ' . " " . $standardQ . ' ' . $yearQ . ' GROUP BY category ORDER BY count(*) DESC LIMIT 10';
// CnCGraph($agency);  
// MethodValueGraph($agency);  
/* biggest contracts  
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 */  
   
$query = 'SELECT "CNID", "description", "value", "agencyName", "category",  
"contractStart", "supplierName"  
FROM contractnotice  
WHERE ' .$yearQ . ' "agencyName" like :agency and "childCN" is null  
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 "<h3>Categories</h3><table> <thead>
  <tr>
  <th>Category</th>
  <th>Contracts Count</th>
  <th>Total Contract Value</th>
  </tr>
  </thead>";
  foreach ($query->fetchAll() as $row) {
  setlocale(LC_MONETARY, 'en_US');
  $value = number_format(doubleval($row['value']), 2);
  $category = urlencode($row['category']);
  echo("<tr>
  <td><B><a href='displayCategory.php?category=$category'>{$row['category']}</a></b></td>
  <td>{$row['count']}</td>
  <td>\$$value</td>
  </tr>");
  }
  echo "</table><br/>";
   
  $query = 'SELECT contractnotice."SONID", min(title) AS title, count(*), sum(value) AS value FROM contractnotice INNER JOIN standingoffers ON contractnotice."SONID" = standingoffers."SONID"
  WHERE "agencyName" LIKE :agency AND ' . " " . $standardQ . ' ' . $yearQ . 'AND contractnotice."SONID" != \'\' GROUP BY contractnotice."SONID"';
  $query = $conn->prepare($query);
  $query->bindParam(":agency", $agency);
  $query->execute();
  databaseError($conn->errorInfo());
  $sonrows = "";
  foreach ($query->fetchAll() as $row) {
  setlocale(LC_MONETARY, 'en_US');
  $value = number_format(doubleval($row['value']), 2);
  $sonrows .= "<tr>
  <td><B><a href=\"displaySON.php?SONID={$row['SONID']}\">{$row['title']}</a></b></td>
  <td>{$row['count']}</td>
  <td>\$$value</td>
  </tr>";
  }
  if (strlen($sonrows) > 1) {
  echo "<h3>Standing Offers/Panels</h3><table> <thead>
  <tr>
  <th>Standing Offer</th>
  <th>Contracts Count</th>
  <th>Total Contract Value</th>
  </tr>
  </thead>$sonrows</table><br/>";
  }
   
  $query = 'SELECT SUM(value) AS value, count(*), text_mode("supplierName") "supplierName", min("supplierABN") AS "supplierABN", (
  CASE WHEN "supplierABN" != 0 THEN "supplierABN"::TEXT ELSE lower("supplierName") END) AS "supplierID" FROM contractnotice
  WHERE ' . $yearQ . " " . $standardQ . ' AND "agencyName" LIKE :agency
  GROUP BY "supplierID" ORDER BY "value" DESC';
  $query = $conn->prepare($query);
  $query->bindParam(":agency", $agency);
  $query->execute();
  databaseError($conn->errorInfo());
  echo "<h3>Suppliers</h3><table> <thead>
  <tr>
  <th>Supplier</th>
  <th>Contracts Count</th>
  <th>Total Contract Value</th>
  </tr>
  </thead>";
  foreach ($query->fetchAll() as $row) {
  setlocale(LC_MONETARY, 'en_US');
  $value = number_format(doubleval($row['value']), 2);
  $supplierID = $row['supplierABN'] . '-' . urlencode($row['supplierName']);
  echo("<tr>
  <td><B><a href=\"displaySupplier.php?supplier=$supplierID\" >{$row['supplierName']}</a></b></td>
  <td>{$row['count']}</td>
  <td>\$$value</td>
  </tr>");
  }
  echo "</table><br/>";
  /*
  * Procurement method in text, seperate Open via SON from Open
  * Consultancies, Confidentialities percentage
  Compliance statistics: amendments, delay in reporting average and number completely late */
   
  $query = 'SELECT "CNID", "description", "value", "agencyName", "category",
  "contractStart", "supplierName"
  FROM contractnotice
  WHERE ' . $yearQ . ' "agencyName" LIKE :agency AND "childCN" IS NULL
  ORDER BY "value" DESC LIMIT 100';
  $query = $conn->prepare($query);
  $query->bindParam(":agency", $agency);
  $query->execute();
  databaseError($conn->errorInfo());
   
  echo "<h3>Contracts</h3><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");
/* /*
   
   
agencies that use alot of consultacies agencies that use alot of consultacies
suppliers that provide alot suppliers that provide alot
how much is spent overall per year how much is spent overall per year
*/ */
   
include_header("Consultancies"); include_header("Consultancies");
$query = ' $query = '
SELECT SUM(value) as value, count(*), min("supplierName"), unnest(string_to_array("consultancyReason",\';\')) reason SELECT SUM(value) as value, count(*), text_mode("supplierName"), unnest(string_to_array("consultancyReason",\';\')) reason
FROM contractnotice where ' .$yearQ . ' "consultancy" = \'Yes\' and "childCN" is null FROM contractnotice where ' .$yearQ . ' "consultancy" = \'Yes\' and "childCN" is null
GROUP BY "supplierABN",reason order by value desc GROUP BY "supplierABN",reason order by value desc
'; ';
   
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
   
echo "<table>"; echo "<table>";
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);
echo ("<tr><td><b>{$row[2]}</b></td><td>{$row[3]}</td><td>{$row[1]} contracts</td><td>\$$value</td></tr>"); echo ("<tr><td><b>{$row[2]}</b></td><td>{$row[3]}</td><td>{$row[1]} contracts</td><td>\$$value</td></tr>");
} }
echo "</table>"; echo "</table>";
include_footer(); include_footer();
?> ?>
   
   
   
<?php <?php
   
include_once("./lib/common.inc.php"); include_once("./lib/common.inc.php");
$query = 'SELECT * $query = 'SELECT *
FROM contractnotice FROM contractnotice
WHERE "CNID" = :CNID LIMIT 1'; WHERE "CNID" = :CNID LIMIT 1';
   
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->bindParam(":CNID", $_REQUEST['CNID']); $query->bindParam(":CNID", $_REQUEST['CNID']);
$query->execute(); $query->execute();
$contractResult = $query->fetch(PDO::FETCH_ASSOC); $contractResult = $query->fetch(PDO::FETCH_ASSOC);
if (!$contractResult) { if (!$contractResult) {
header("Status: 404 Not Found"); header("Status: 404 Not Found");
header("HTTP/1.0 404 Not Found"); header("HTTP/1.0 404 Not Found");
include_header("Contract Not Found"); include_header("Contract Not Found");
echo "<center><h1>No Contract Notice with that ID found</h1></center>"; echo "<center><h1>No Contract Notice with that ID found</h1></center>";
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} else { } else {
$description = ucsmart($contractResult["description"]); $description = ucsmart($contractResult["description"]);
include_header($description); include_header($description);
echo '<center><h1>'.$description.'</h1></center> echo '<center><h1>'.$description.'</h1></center>
<div about="http://contracts.disclosurelo.gs/displayContract.php?CNID='.$contractResult["CNID"].'" typeof="pc:Contract">'; <div about="http://contracts.disclosurelo.gs/displayContract.php?CNID='.$contractResult["CNID"].'" typeof="pc:Contract">';
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
foreach (array_filter($contractResult) as $key => $value) { foreach (array_filter($contractResult) as $key => $value) {
echo "<b>$key</b>&nbsp;"; echo "<b>$key</b>&nbsp;";
switch ($key) { switch ($key) {
case "supplierABN": case "supplierABN":
break; break;
case "supplierName": case "supplierName":
echo ' echo '
<a href="displaySupplier.php?supplier=' . $contractResult['supplierABN'] . '-' . urlencode($contractResult['supplierName']) . '"> <a href="displaySupplier.php?supplier=' . $contractResult['supplierABN'] . '-' . urlencode($contractResult['supplierName']) . '">
<span rel="pc:contractingAuthority" typeof="gr:BusinessEntity"> <span rel="pc:contractingAuthority" typeof="gr:BusinessEntity">
<span property="gr:legalName">' <span property="gr:legalName">'
. $contractResult['supplierName'] . . $contractResult['supplierName'] .
'</span>'. '</span>'.
(isset($contractResult['supplierABN']) && $contractResult['supplierABN'] != '' ? ' (ABN: <span property="br:officialNumber" lang="">'.$contractResult['supplierABN'].'</span>)' : '') (isset($contractResult['supplierABN']) && $contractResult['supplierABN'] != '' ? ' (ABN: <span property="br:officialNumber" lang="">'.$contractResult['supplierABN'].'</span>)' : '')
.'</span></a>'; .'</span></a>';
break; break;
case "CNID": case "CNID":
echo '<span property="pc:referenceNumber" lang="">'.$value.'</span>'; echo '<span property="pc:referenceNumber" lang="">'.$value.'</span>';
break;  
case "categoryUNSPSC":  
break; break;
case "category": case "category":
echo '<span rel="pc:mainObject" resource="[unspsc:'.$contractResult["categoryUNSPSC"].']">'.$value.'</span>'; echo '<span rel="pc:mainObject" resource="[unspsc:'.$contractResult["categoryUNSPSC"].']">'.$value.'</span>';
break; break;
case "SONID": case "SONID":
echo '<a href="displaySON.php?SONID=' . urlencode($value) . '">' . $value . "</a>"; echo '<a href="displaySON.php?SONID=' . urlencode($value) . '">' . $value . "</a>";
break; break;
case "agencyName": case "agencyName":
echo '<a href="displayAgency.php?agency=' . urlencode($value) . '">' . $value . "</a>"; echo '<a href="displayAgency.php?agency=' . urlencode($value) . '">' . $value . "</a>";
break; break;
case "contractStart": case "contractStart":
echo '<span property="pc:startDate" content="'.$value.'" datatype="xsd:date">'.$value.'</span>'; echo '<span property="pc:startDate" content="'.$value.'" datatype="xsd:date">'.$value.'</span>';
break; break;
case "contractEnd": case "contractEnd":
echo '<span property="pc:endDate" content="'.$value.'" datatype="xsd:date">'.$value.'</span>'; echo '<span property="pc:endDate" content="'.$value.'" datatype="xsd:date">'.$value.'</span>';
break; break;
case "value": case "value":
echo '<span rel="pc:agreedPrice" typeof="gr:PriceSpecification"> echo '<span rel="pc:agreedPrice" typeof="gr:PriceSpecification">
<span property="gr:hasCurrency" content="AUD" lang="">$ </span> <span property="gr:hasCurrency" content="AUD" lang="">$ </span>
<span property="gr:hasCurrencyValue" content="'.doubleval($value).'" datatype="xsd:float">' . number_format(doubleval($value), 2) <span property="gr:hasCurrencyValue" content="'.doubleval($value).'" datatype="xsd:float">' . number_format(doubleval($value), 2)
.'</span></span>'; .'</span></span>';
break; break;
case "description": case "description":
echo '<span property="dcterms:title">'.$value.'</span>'; echo '<span property="dcterms:title">'.$value.'</span>';
break; break;
default: default:
echo str_replace(" ", "<br>", ucsmart($value)); echo str_replace(" ", "<br>", ucsmart($value));
} }
echo "<br>\n"; echo "<br>\n";
} }
echo '<br><a href="https://www.tenders.gov.au/?event=public.advancedsearch.keyword&keyword=CN' . $_REQUEST['CNID'] . '"> View original record @ tenders.gov.au</a><br> echo '<br><a href="https://www.tenders.gov.au/?event=public.advancedsearch.keyword&keyword=CN' . $_REQUEST['CNID'] . '"> View original record @ tenders.gov.au</a><br>
</div>'; </div>';
   
/*$query = $solr_client->createMoreLikeThis(); /*$query = $solr_client->createMoreLikeThis();
   
$query->setQuery('id:'.$_REQUEST['CNID']); $query->setQuery('id:'.$_REQUEST['CNID']);
$query->setMltFields('description'); $query->setMltFields('description');
$query->setMinimumDocumentFrequency(1); $query->setMinimumDocumentFrequency(1);
$query->setMinimumTermFrequency(1); $query->setMinimumTermFrequency(1);
$query->setInterestingTerms('description'); $query->setInterestingTerms('description');
$query->setMatchInclude(true); $query->setMatchInclude(true);
   
// this executes the query and returns the result // this executes the query and returns the result