From: root Date: Sat, 25 Mar 2017 00:25:12 +0000 Subject: unspsc update X-Git-Url: http://maxious.lambdacomplex.org/git/?p=contractdashboard.git&a=commitdiff&h=dc59c2d1578af3ea48164a05030550532e932402 --- unspsc update --- --- a/admin/updateUNSPSC.php +++ b/admin/updateUNSPSC.php @@ -12,6 +12,8 @@ // some Australian spellings $isiz = str_replace("iz", "is", $row['Title']); $unspsc[$isiz] = $row['UNSPSC']; + $iseize = str_replace("ize", "ise", $row['Title']); + $unspsc[$iseize] = $row['UNSPSC']; $filfill = str_replace("fill", "fil", $row['Title']); $unspsc[$filfill] = $row['UNSPSC']; $ampersand = str_replace("&", "and", $row['Title']); @@ -20,6 +22,8 @@ $unspsc[$defence] = $row['UNSPSC']; $armor = str_replace("rmored", "rmoured", $row['Title']); $unspsc[$armor] = $row['UNSPSC']; + $labour = str_replace("labor", "labour", $row['Title']); + $unspsc[$labour] = $row['UNSPSC']; $erre = str_replace("er", "re", $row['Title']); $unspsc[$erre] = $row['UNSPSC']; $center = str_replace("center", "centre", $row['Title']); @@ -38,6 +42,14 @@ $airo = str_replace("airplane", "aeroplane", $row['Title']); $unspsc[$airo] = $row['UNSPSC']; // some divergence from standard + $services = str_replace( " services", "", $row['Title']); + $unspsc[$services] = $row['UNSPSC']; + $microa = str_replace( "micro assemblies", "microassemblies", $row['Title']); + $unspsc[$microa] = $row['UNSPSC']; + $lightb = str_replace( "light bulbs", "lightbulbs", $row['Title']); + $unspsc[$lightb] = $row['UNSPSC']; + $kitchen = str_replace( "domestic kitchenware and kitchen supplies", "domestic kitchenware", $row['Title']); + $unspsc[$kitchen] = $row['UNSPSC']; $forensicit = str_replace("Information technology consultation services", "Forensic IT Services", $row['Title']); $unspsc[$forensicit] = $row['UNSPSC']; $powercable = str_replace( "Power cable", "Power cable installation and supply", $row['Title']); --- a/displayAgency.php +++ b/displayAgency.php @@ -16,6 +16,7 @@ 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 "agencyName" LIKE :agency AND ' . " $yearQ $standardQ " ; --- a/displayCategory.php +++ b/displayCategory.php @@ -1,18 +1,71 @@

".$_REQUEST['category']."

"; - $query = 'SELECT "CNID", description, value, "agencyName", category, "contractStart", "supplierName" + + // if UNSPSC code known show, say if is a parent and offer to include children, if child link to parent + $query = 'SELECT key, d."UNSPSC", "Title" AS category FROM +(SELECT \'categoryUNSPSC\' AS key, "categoryUNSPSC"::TEXT AS "UNSPSC" FROM contractnotice WHERE category = :category +UNION SELECT \'parentUNSPSC\', substr( "categoryUNSPSC"::TEXT, 0, 5 )||\'0000\'::TEXT AS "parentUNSPSC" FROM contractnotice WHERE category = :category +UNION SELECT \'grandparentUNSPSC\', substr( "categoryUNSPSC"::TEXT, 0, 3 )||\'000000\'::TEXT AS "grandparentUNSPSC" +FROM contractnotice WHERE category = :category ) d +INNER JOIN (SELECT "Title", "UNSPSC" FROM "UNSPSCcategories" ) c ON c."UNSPSC"=d."UNSPSC"::INTEGER'; + $query = $conn->prepare($query); + $query->bindParam(":category", $_REQUEST['category']); + $query->execute(); + databaseError($conn->errorInfo()); + $unspsc = Array(); + foreach ($query->fetchAll() as $d) { + $unspsc[$d['key']] = $d; + } + + + include_header($_REQUEST['category'] . " goods and services"); + if ($unspsc['categoryUNSPSC']) { + echo "

{$_REQUEST['category']} ({$unspsc['categoryUNSPSC']['UNSPSC']})

"; + + if ($unspsc['parentUNSPSC']['UNSPSC'] != $unspsc['categoryUNSPSC']['UNSPSC']) { + echo "Parent Category: {$unspsc['parentUNSPSC']['UNSPSC']} {$unspsc['parentUNSPSC']['category']}
"; + } + if ($unspsc['grandparentUNSPSC']['UNSPSC'] != $unspsc['categoryUNSPSC']['UNSPSC']) { + echo "Grandparent Category: {$unspsc['grandparentUNSPSC']['UNSPSC']} {$unspsc['grandparentUNSPSC']['category']}
"; + } + + } else { + echo "

{$_REQUEST['category']}

"; + } + + $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 category = :category AND ' . " $yearQ $standardQ "; + $query = $conn->prepare($query); + $query->bindParam(":category", $_REQUEST['category']); + $query->execute(); + databaseError($conn->errorInfo()); + + $stats = reset($query->fetchAll()); + show_stats($stats); + + + $query = 'SELECT "CNID", description, value, "agencyName", category, "contractStart", "supplierName" FROM contractnotice - WHERE '.$yearQ.' "childCN" is null - AND category = :category - ORDER BY value DESC'; -$query = $conn->prepare($query); -$query->bindParam(":category", $_REQUEST['category']); - $query->execute(); - databaseError($conn->errorInfo()); - + WHERE ' . $yearQ . ' "childCN" IS NULL + AND CATEGORY = :CATEGORY + ORDER BY VALUE DESC'; + $query = $conn->prepare($query); + $query->bindParam(":CATEGORY", $_REQUEST['category']); + $query->execute(); + databaseError($conn->errorInfo()); + echo " @@ -23,42 +76,42 @@ "; - foreach ($query->fetchAll() as $row) { - setlocale(LC_MONETARY, 'en_US'); - $value = number_format(doubleval($row['value']) , 2); - echo (" + foreach ($query->fetchAll() as $row) { + setlocale(LC_MONETARY, 'en_US'); + $value = number_format(doubleval($row['value']), 2); + echo(""); - } - echo "
Contract Notice NumberSupplier
{$row['CNID']} {$row['description']} \$$value{$row['agencyName']} {$row['contractStart']} {$row['supplierName']}
"; + } + echo ""; } else { /* split by main categories */ include_header("Categories"); -$query = 'SELECT sum(value), category + $query = 'SELECT sum(value), category FROM contractnotice -WHERE '.$yearQ.' "childCN" is null -GROUP BY category ORDER BY sum(value) DESC '; -$query = $conn->prepare($query); - $query->execute(); - databaseError($conn->errorInfo()); - echo " +WHERE ' . $yearQ . ' "childCN" IS NULL +GROUP BY CATEGORY ORDER BY sum(VALUE) DESC '; + $query = $conn->prepare($query); + $query->execute(); + databaseError($conn->errorInfo()); + echo "
"; - foreach ($query->fetchAll() as $row) { - setlocale(LC_MONETARY, 'en_US'); - $value = number_format(doubleval($row[0]) , 2); - echo (""); -} -echo "
Category Total Contracts Value
{$row[1]}\$$value
"; + foreach ($query->fetchAll() as $row) { + setlocale(LC_MONETARY, 'en_US'); + $value = number_format(doubleval($row[0]), 2); + echo("{$row[1]}\$$value"); + } + echo ""; } include_footer(); ?> --- a/displaySON.php +++ b/displaySON.php @@ -20,6 +20,7 @@ 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 " ; @@ -84,9 +85,11 @@ } 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" - UNION SELECT abn AS "supplierABN",name AS "supplierName",0 AS sum,0 AS value FROM standingoffer_suppliers + $query = 'SELECT min("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, NULL AS "supplierID" FROM standingoffer_suppliers WHERE "SONID" = :SONID AND abn NOT IN (SELECT DISTINCT "supplierABN" AS abn FROM contractnotice WHERE "SONID" = :SONID)'; $query = $conn->prepare($query); $query->bindParam(":SONID", $_REQUEST['SONID']); --- 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 . " " . $yearQ . " " .$standardQ ; $query = $conn->prepare($query); - if ($supplierParts[0] > 0) { + if (isset($supplierABN)) { $query->bindParam(":supplierABN", $supplierABN); } else { $query->bindParam(":supplierName", $supplierName); @@ -50,7 +54,7 @@ $query = 'SELECT category, min("categoryUNSPSC") AS "categoryUNSPSC", count(*) AS count, sum(value) AS value FROM contractnotice WHERE ' . $supplierQ . " $yearQ $standardQ ". ' GROUP BY category ORDER BY count(*) DESC LIMIT 10'; $query = $conn->prepare($query); - if ($supplierParts[0] > 0) { + if (isset($supplierABN)) { $query->bindParam(":supplierABN", $supplierABN); } else { $query->bindParam(":supplierName", $supplierName); @@ -79,17 +83,18 @@ echo "
"; - $query = 'SELECT SUM("value") AS "value", count(*), text_mode(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) { +GROUP BY abn ORDER BY SUM("value") DESC';*/ + $query = 'SELECT SUM("value") AS "value", count(*), "agencyName" AS agencyname FROM contractnotice +WHERE ' . $yearQ . ' ' . $supplierQ . ' "childCN" IS NULL GROUP BY "agencyName" ORDER BY SUM("value") DESC'; + + $query = $conn->prepare($query); + if (isset($supplierABN)) { $query->bindParam(":supplierABN", $supplierABN); } else { $query->bindParam(":supplierName", $supplierName); } - } $query->execute(); databaseError($conn->errorInfo()); @@ -118,7 +123,7 @@ $query = $conn->prepare($query); - if ($supplierParts[0] > 0) { + if (isset($supplierABN)) { $query->bindParam(":supplierABN", $supplierABN); } else { $query->bindParam(":supplierName", $supplierName); @@ -163,7 +168,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 @@ -99,7 +99,9 @@ } function show_stats($stats) { - echo "
"; + 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 "%
"; @@ -136,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; @@ -184,7 +190,7 @@ pcdt: http://purl.org/procurement/public-contracts-datatypes#"> <?php echo $title; ?> - Contract Dashboard - + --- a/search.php +++ b/search.php @@ -67,11 +67,15 @@ "contractStart", "supplierName" FROM contractnotice WHERE ' .$yearQ . ' to_tsvector(\'english\', description) @@ plainto_tsquery(\'english\', :keyword) and "childCN" is null - ORDER BY "value" DESC limit 100'; + ORDER BY "value" DESC limit 1000'; $query = $conn->prepare($query); $query->bindParam(":keyword", $keyword); $query->execute(); databaseError($conn->errorInfo()); +if ($query->rowCount() > 999) { +// if 1000 records warn too many results +print " More than 1000 results found so only first 1000 shown. Please filter by year or keyword to see all results "; +} echo ''; foreach ($query->fetchAll() as $row) { //print_r($row);