more panel/category tables
more panel/category tables

--- a/displayAgency.php
+++ b/displayAgency.php
@@ -1,13 +1,13 @@
 <?php
 
-include_once ("./lib/common.inc.php");
+include_once("./lib/common.inc.php");
 if ($_REQUEST['agency']) {
 
     $agency = htmlentities(strip_tags($_REQUEST['agency']));
     include_header($agency);
-echo '<center><h1>'.$agency.'</h1></center>';
+    echo '<center><h1>' . $agency . '</h1></center>';
     $query = 'SELECT category, min("categoryUNSPSC")  AS "categoryUNSPSC", count(*) AS count, sum(value) AS value  FROM contractnotice 
-  WHERE "agencyName" like :agency AND '. " " . $standardQ . ' GROUP BY category order by count(*) desc limit 10';
+  WHERE "agencyName" LIKE :agency AND ' . " " . $standardQ . ' ' . $yearQ . ' GROUP BY category ORDER BY count(*) DESC LIMIT 10';
     $query = $conn->prepare($query);
     $query->bindParam(":agency", $agency);
     $query->execute();
@@ -32,9 +32,36 @@
     </tr>");
     }
     echo "</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
+
+    $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);
@@ -50,7 +77,7 @@
     foreach ($query->fetchAll() as $row) {
         setlocale(LC_MONETARY, 'en_US');
         $value = number_format(doubleval($row['value']), 2);
-$supplierID = $row['supplierABN'].'-'. urlencode($row['supplierName']);
+        $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>
@@ -58,19 +85,16 @@
     </tr>");
     }
     echo "</table><br/>";
-/*
- *     Categories table
- *  SONs/Panels used table
-    * Replace pie chart with percent count/count/percent value/value table
-    * Procurement method in text, seperate Open via SON from Open
-    * Consultancies, Confidentialities percentage
-      Compliance statistics: amendments, delay in reporting average and number completely late */
+    /*
+        * 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';
+    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();
@@ -89,7 +113,7 @@
     foreach ($query->fetchAll() as $row) {
         setlocale(LC_MONETARY, 'en_US');
         $value = number_format(doubleval($row['value']), 2);
-        echo ("<tr>
+        echo("<tr>
     <td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td>
     <td><b>{$row['description']}</b></a></td>
     <td>\$$value</td><td>{$row['agencyName']}</td>
@@ -106,7 +130,7 @@
     agenciesGraph();
     $query = 'SELECT SUM("value"), "agencyName"
 FROM contractnotice
-WHERE ' .$yearQ . ' "childCN" is null 
+WHERE ' . $yearQ . ' "childCN" IS NULL 
 GROUP BY "agencyName" ';
     $query = $conn->prepare($query);
     $query->execute();
@@ -121,7 +145,7 @@
         setlocale(LC_MONETARY, 'en_US');
         $value = number_format(doubleval($row[0]), 2);
         $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>";
 }

--- a/displaySON.php
+++ b/displaySON.php
@@ -9,7 +9,11 @@
     $title = reset($query->fetchAll())['title'];
     include_header($title);
     echo "<center><h1>" . $_REQUEST['SONID'] . " - " . $title . "</h1></center>";
-
+    echo '<br><a href="https://www.tenders.gov.au/?event=public.advancedsearch.CNSONRedirect&type=sonSearchEvent&SONID=' . $_REQUEST['SONID'] . '"> View original record @ tenders.gov.au</a><br>';
+    /*
+     * Procurement method in text, seperate Open via SON from Open
+     * Consultancies, Confidentialities percentage
+     */
     $query = 'SELECT category, min("categoryUNSPSC")  AS "categoryUNSPSC", count(*) AS count, sum(value) AS value 
 FROM contractnotice 
 WHERE "SONID" = :SONID 
@@ -45,7 +49,6 @@
     $query->bindParam(":SONID", $_REQUEST['SONID']);
     $query->execute();
     databaseError($conn->errorInfo());
-    echo '<br><a href="https://www.tenders.gov.au/?event=public.advancedsearch.CNSONRedirect&type=sonSearchEvent&SONID=' . $_REQUEST['SONID'] . '"> View original record @ tenders.gov.au</a><br>';
 
     echo "<h3>Suppliers</h3><table>  <thead>
     <tr>
@@ -100,7 +103,7 @@
      split by main categories
     */
     include_header("Standing Offers");
-    $query = 'SELECT sum(value), count(*), contractnotice."SONID", min(title) AS title
+    $query = 'SELECT sum(value), count(*), contractnotice."SONID", min(title) AS title, text_mode(category) as category
 FROM contractnotice INNER JOIN standingoffers ON contractnotice."SONID" = standingoffers."SONID"
 WHERE ' . $yearQ . ' "childCN" IS NULL AND contractnotice."SONID" != \'\'
 GROUP BY contractnotice."SONID" ORDER BY sum(VALUE) DESC ';
@@ -110,6 +113,7 @@
     echo "<table>  <thead>
     <tr>
       <th>SONID</th>
+      <th>Main category</th>
       <th>Total Contracts Value</th>
       <th>Number of Contracts</th>
     </tr>
@@ -117,7 +121,9 @@
     foreach ($query->fetchAll() as $row) {
         setlocale(LC_MONETARY, 'en_US');
         $value = number_format(doubleval($row['sum']), 2);
-        echo("<tr><td><A href=\"displaySON.php?SONID={$row['SONID']}\"><b>{$row['title']}</b></a></td><td>\$$value</td><td>{$row['count']}</td></tr>");
+        $title = $row['SONID'];
+        if (strlen($row['title']) > 1) $title = $row['title'];
+        echo("<tr><td><A href=\"displaySON.php?SONID={$row['SONID']}\"><b>$title</b></a></td><td>{$row['category']}</td><td>\$$value</td><td>{$row['count']}</td></tr>");
     }
     echo "</table>";
 }

--- a/displaySupplier.php
+++ b/displaySupplier.php
@@ -14,8 +14,15 @@
     }
     include_header(str_replace("%", "", $title));
     echo '<center><h1>' . str_replace("%", "", $title) . '</h1></center>';
+if ($supplierABN) {
+    $query = 'SELECT distinct on (lower("supplierName")) "supplierName" from contractnotice where "supplierABN" = :supplierABN';
+    $query = $conn->prepare($query);
+    $query->bindParam(":supplierABN", $supplierABN);
+    $query->execute();
+    databaseError($conn->errorInfo());
+    echo "Also known as: ".implode(', ', $query->fetchAll(PDO::FETCH_COLUMN, 0));
+}
     /*
-     * Common names and uncommon names
      * Procurement method in text, seperate Open via SON from Open
      * Consultancies, Confidentialities percentage
      */

--- a/lib/common.inc.php
+++ b/lib/common.inc.php
@@ -4,7 +4,7 @@
 error_reporting(E_ALL ^ E_NOTICE);
 
 
-$conn = new PDO("pgsql:dbname=contractdashboard;user=alex;host=localhost");
+$conn = new PDO("pgsql:dbname=contractdashboard;user=postgres;password=snmc;host=localhost");
 
 if (!$conn) {
     die("A database error occurred.\n");