From: root Date: Wed, 08 Feb 2017 10:33:22 +0000 Subject: fix supplier ID, add total value stat X-Git-Url: https://maxious.lambdacomplex.org/git/?p=contractdashboard.git&a=commitdiff&h=115037ceeb1fc65f38bca7cab5a4d6e0814f9bda --- fix supplier ID, add total value stat --- --- a/displayAgency.php +++ b/displayAgency.php @@ -6,12 +6,6 @@ $agency = htmlentities(strip_tags($_REQUEST['agency'])); include_header($agency); echo '

' . $agency . '

'; - $query = 'SELECT category, min("categoryUNSPSC") AS "categoryUNSPSC", count(*) AS count, sum(value) AS value FROM contractnotice - 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(); - databaseError($conn->errorInfo()); $query = ' SELECT @@ -22,16 +16,27 @@ sum((("procurementMethod" = \'Open\' OR "procurementMethod" = \'Open tender\') AND "SONID" IS NOT null)::int) AS "openSON", sum(("procurementMethod" = \'Prequalified tender\' OR "procurementMethod" = \'Select\')::INT) AS prequalified, sum(("procurementMethod" = \'Direct\' OR "procurementMethod" = \'Limited tender\')::int) AS limited, +sum("value") as total_value, COUNT(*) AS total FROM contractnotice -WHERE "supplierABN" = \'51194660183\' - '; + WHERE "agencyName" LIKE :agency AND ' . " $yearQ $standardQ " ; + $query = $conn->prepare($query); + $query->bindParam(":agency", $agency); + $query->execute(); + databaseError($conn->errorInfo()); + + $stats = reset($query->fetchAll()); + show_stats($stats); /* - * 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 category, min("categoryUNSPSC") AS "categoryUNSPSC", count(*) AS count, sum(value) AS value FROM contractnotice + WHERE "agencyName" LIKE :agency AND ' . " $yearQ $standardQ " . ' GROUP BY category ORDER BY count(*) DESC LIMIT 10'; + $query = $conn->prepare($query); + $query->bindParam(":agency", $agency); + $query->execute(); + databaseError($conn->errorInfo()); echo "

Categories

@@ -52,7 +57,7 @@ echo "
Category

"; $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"'; +WHERE "agencyName" LIKE :agency AND ' . " $yearQ $standardQ " . 'AND contractnotice."SONID" != \'\' GROUP BY contractnotice."SONID"'; $query = $conn->prepare($query); $query->bindParam(":agency", $agency); $query->execute(); --- a/displayProcurementMethod.php +++ b/displayProcurementMethod.php @@ -12,7 +12,7 @@ include_header("Procurement Methods"); $query = 'SELECT SUM(value) as value, "procurementMethod" FROM contractnotice -WHERE "childCN" is null +WHERE ' . $yearQ. " ". $standardQ .' GROUP BY "procurementMethod"'; $query = $conn->prepare($query); --- a/displaySON.php +++ b/displaySON.php @@ -10,13 +10,31 @@ include_header($title); echo "

" . $_REQUEST['SONID'] . " - " . $title . "

"; echo '
View original record @ tenders.gov.au
'; - /* - * Procurement method in text, seperate Open via SON from Open - * Consultancies, Confidentialities percentage - */ + + $query = ' + SELECT +sum((consultancy = \'Yes\')::int) AS consultancy, +sum(("confidentialityContract" = \'Yes\')::int) AS "confidentialityContract", +sum(("confidentialityOutputs" = \'Yes\')::int) AS "confidentialityOutputs", +sum((("procurementMethod" = \'Open\' OR "procurementMethod" = \'Open tender\') AND "SONID" IS null)::int) AS open, +sum((("procurementMethod" = \'Open\' OR "procurementMethod" = \'Open tender\') AND "SONID" IS NOT null)::int) AS "openSON", +sum(("procurementMethod" = \'Prequalified tender\' OR "procurementMethod" = \'Select\')::INT) AS prequalified, +sum(("procurementMethod" = \'Direct\' OR "procurementMethod" = \'Limited tender\')::int) AS limited, +sum("value") as total_value, +COUNT(*) AS total +FROM contractnotice + WHERE "SONID" = :SONID AND ' . " $yearQ $standardQ " ; + $query = $conn->prepare($query); + $query->bindParam(":SONID", $_REQUEST['SONID']); + $query->execute(); + databaseError($conn->errorInfo()); + + $stats = reset($query->fetchAll()); + show_stats($stats); + $query = 'SELECT category, min("categoryUNSPSC") AS "categoryUNSPSC", count(*) AS count, sum(value) AS value FROM contractnotice -WHERE "SONID" = :SONID +WHERE "SONID" = :SONID AND ' . " $yearQ $standardQ " . ' GROUP BY category'; $query = $conn->prepare($query); $query->bindParam(":SONID", $_REQUEST['SONID']); @@ -41,8 +59,36 @@ } echo "
"; - $query = 'SELECT "supplierABN", text_mode("supplierName") AS "supplierName", count(*), sum(value) AS value FROM contractnotice - WHERE ' . $yearQ . ' "childCN" IS NULL AND "SONID" = :SONID GROUP BY "supplierABN" + $query = 'SELECT text_mode(contractnotice."agencyName") AS agencyname, count(*), sum(value) AS value FROM contractnotice + WHERE ' . $yearQ . ' "childCN" IS NULL AND "SONID" = :SONID GROUP BY "agencyName"'; + $query = $conn->prepare($query); + $query->bindParam(":SONID", $_REQUEST['SONID']); + $query->execute(); + databaseError($conn->errorInfo()); + + echo "

Agencies

+ + + + + + "; + foreach ($query->fetchAll() as $row) { + setlocale(LC_MONETARY, 'en_US'); + $value = number_format(doubleval($row['value']), 2); + + echo(" + + + + "); + } + echo "
AgencyContracts CountTotal Contract Value
{$row['agencyname']}{$row['count']}\$$value

"; + + $query = 'SELECT "supplierABN", text_mode("supplierName") AS "supplierName", count(*), sum(value) AS value, + (CASE WHEN "supplierABN" != 0 THEN "supplierABN"::TEXT ELSE lower("supplierName") END) AS "supplierID" +FROM contractnotice + WHERE ' . $yearQ . ' "childCN" IS NULL AND "SONID" = :SONID GROUP BY "supplierID" UNION SELECT abn AS "supplierABN",name AS "supplierName",0 AS sum,0 AS value FROM standingoffer_suppliers WHERE "SONID" = :SONID AND abn NOT IN (SELECT DISTINCT "supplierABN" AS abn FROM contractnotice WHERE "SONID" = :SONID)'; $query = $conn->prepare($query); @@ -67,6 +113,7 @@ \$$value "); } + echo "

Contracts

--- a/displaySupplier.php +++ b/displaySupplier.php @@ -4,8 +4,11 @@ if ($_REQUEST['supplier']) { $supplierS = htmlentities(strip_tags($_REQUEST['supplier'])); $title = $supplierName; - if ($supplierABN) { - $query = 'SELECT text_mode("supplierName") AS "supplierName" FROM contractnotice WHERE "supplierABN" = :supplierABN GROUP BY "supplierABN"'; + if (isset($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(); @@ -14,7 +17,7 @@ } include_header(str_replace("%", "", $title)); echo '

' . str_replace("%", "", $title) . '

'; -if ($supplierABN) { +if (isset($supplierABN)) { $query = 'SELECT distinct on (lower("supplierName")) "supplierName" from contractnotice where "supplierABN" = :supplierABN'; $query = $conn->prepare($query); $query->bindParam(":supplierABN", $supplierABN); @@ -32,11 +35,12 @@ sum((("procurementMethod" = \'Open\' OR "procurementMethod" = \'Open tender\') AND "SONID" IS NOT null)::int) AS "openSON", sum(("procurementMethod" = \'Prequalified tender\' OR "procurementMethod" = \'Select\')::INT) AS prequalified, sum(("procurementMethod" = \'Direct\' OR "procurementMethod" = \'Limited tender\')::int) AS limited, +sum("value") as total_value, COUNT(*) AS total FROM contractnotice -WHERE' . $supplierQ . " " . $standardQ ; - $query = $conn->prepare($query); - if ($supplierParts[0] > 0) { +WHERE' . $supplierQ . " " . $yearQ . " " .$standardQ ; + $query = $conn->prepare($query); + if (isset($supplierABN)) { $query->bindParam(":supplierABN", $supplierABN); } else { $query->bindParam(":supplierName", $supplierName); @@ -48,9 +52,9 @@ show_stats($stats); $query = 'SELECT category, min("categoryUNSPSC") AS "categoryUNSPSC", count(*) AS count, sum(value) AS value FROM contractnotice - WHERE ' . $supplierQ . " " . $standardQ . ' GROUP BY category ORDER BY count(*) DESC LIMIT 10'; - $query = $conn->prepare($query); - if ($supplierParts[0] > 0) { + WHERE ' . $supplierQ . " $yearQ $standardQ ". ' GROUP BY category ORDER BY count(*) DESC LIMIT 10'; + $query = $conn->prepare($query); + if (isset($supplierABN)) { $query->bindParam(":supplierABN", $supplierABN); } else { $query->bindParam(":supplierName", $supplierName); @@ -79,12 +83,12 @@ echo "
Contract Notice Number

"; - $query = 'SELECT SUM("value") AS "value", count(*), MAX(contractnotice."agencyName") AS agencyname FROM contractnotice JOIN agency_nametoabn ON contractnotice."agencyName"=agency_nametoabn."agencyName" + $query = 'SELECT SUM("value") AS "value", count(*), text_mode(contractnotice."agencyName") AS agencyname FROM contractnotice JOIN agency_nametoabn ON contractnotice."agencyName"=agency_nametoabn."agencyName" WHERE ' . $yearQ . ' ' . $supplierQ . ' "childCN" IS NULL GROUP BY abn ORDER BY SUM("value") DESC'; $query = $conn->prepare($query); if (count($supplierParts) > 0) { - if ($supplierParts[0] > 0) { + if (isset($supplierABN)) { $query->bindParam(":supplierABN", $supplierABN); } else { $query->bindParam(":supplierName", $supplierName); @@ -118,7 +122,7 @@ $query = $conn->prepare($query); - if ($supplierParts[0] > 0) { + if (isset($supplierABN)) { $query->bindParam(":supplierABN", $supplierABN); } else { $query->bindParam(":supplierName", $supplierName); @@ -163,7 +167,7 @@ $query = $conn->prepare($query); - if ($supplierParts[0] > 0) { + if (isset($supplierABN)) { $query->bindParam(":supplierABN", $supplierABN); } else { $query->bindParam(":supplierName", $supplierName); --- a/lib/common.inc.php +++ b/lib/common.inc.php @@ -4,11 +4,7 @@ error_reporting(E_ALL ^ E_NOTICE); -$conn = new PDO("pgsql:dbname=contractdashboard;user=postgres;password=snmc;host=localhost"); - -if (!$conn) { - die("A database error occurred.\n"); -} +include('db.inc.php'); define('ROOT', pathinfo(__FILE__, PATHINFO_DIRNAME)); if (strstr($_SERVER['PHP_SELF'], "labs/") || strstr($_SERVER['PHP_SELF'], "admin/") || strstr($_SERVER['PHP_SELF'], "heuristics/")) { @@ -102,6 +98,39 @@ return $totale; } +function show_stats($stats) { + setlocale(LC_MONETARY, 'en_US'); + $value = number_format(doubleval($stats['total_value']) , 2); + echo "
{$stats['total']} contracts, total value $$value
"; + if ($stats['consultancy'] > 0) { + echo "Consultancies: {$stats['consultancy']} contracts, ".percent($stats['consultancy'],$stats['total']); + echo "%
"; + } + if ($stats['confidentialityContract']+$stats['confidentialityOutputs'] > 0) { + $confidentialities = $stats['confidentialityContract']+$stats['confidentialityOutputs']; + echo "Confidentialities: $confidentialities contracts, ".percent( $confidentialities,$stats['total'])."%"; + echo "( {$stats['confidentialityContract']} on the contract, {$stats['confidentialityOutputs']} on the outputs)"; + echo "
"; + } + echo "Procurement methods: "; + if ($stats['open'] > 0) { + echo "Open {$stats['open']} contracts, ".percent($stats['open'],$stats['total']); + echo "%, "; + } + if ($stats['openSON'] > 0) { + echo "Open via SON {$stats['openSON']} contracts, ".percent($stats['openSON'],$stats['total']); + echo "%, "; + } + if ($stats['prequalified'] > 0) { + echo "Prequalified {$stats['prequalified']} contracts, ".percent($stats['prequalified'],$stats['total']); + echo "%, "; + } + if ($stats['limited'] > 0) { + echo "limited {$stats['limited']} contracts, ".percent($stats['limited'],$stats['total']); + echo "%, "; + } +} + // magic query modifiers $agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING); if ($agency != "") @@ -109,13 +138,17 @@ $supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING); if ($supplier != "") { + if ($supplier[0] !== '-') { $supplierParts = explode("-", $supplier); - $supplierName = "%" . $supplierParts[1] . "%"; - $supplierABN = $supplierParts[0]; - if ($supplierParts[0] > 0) - $supplierQ = ' "supplierABN" = :supplierABN AND '; - else - $supplierQ = ' "supplierName" ILIKE :supplierName AND '; + + $supplierABN = array_shift($supplierParts); + $supplierName = "%" . implode('-',$supplierParts) . "%"; + + $supplierQ = ' "supplierABN" = :supplierABN AND '; + } else { + $supplierName = "%" . substr($supplier,1) . "%"; + $supplierQ = ' "supplierName" ILIKE :supplierName AND '; + } } $startYear = 2007; @@ -157,6 +190,7 @@ pcdt: http://purl.org/procurement/public-contracts-datatypes#"> <?php echo $title; ?> - Contract Dashboard + @@ -288,7 +322,7 @@