Use correct tuples of UNSPSC for export/bubbletree
[contractdashboard.git] / exportData.csv.php
blob:a/exportData.csv.php -> blob:b/exportData.csv.php
--- a/exportData.csv.php
+++ b/exportData.csv.php
@@ -10,26 +10,20 @@
 foreach ($unspscresult->fetchAll() as $row) {
     $unspsc[$row['UNSPSC']] = $row['Title'];
 }
-
+/*SELECT count(*), extract("week" from "publishDate") as week,extract("year" from "publishDate") as year
+FROM contractnotice   
+where "childCN" is null group by week, year order by year, week*/
 $query = $conn->prepare('
-SELECT "CNID",contractnotice."agencyName",agency.abn as "agencyABN",
+SELECT "CNID",contractnotice."agencyName",agency_nametoabn.abn as "agencyABN",
 EXTRACT(EPOCH FROM "publishDate") as "publishDate",
 EXTRACT(EPOCH FROM "contractStart") as "contractStart",
 EXTRACT(EPOCH FROM "contractEnd") as "contractEnd",
-value,description,"procurementMethod",category,"categoryUNSPSC",
-(substr( "categoryUNSPSC"::text, 0, 2 ) || \'000000\'::text) as "cat1",  
- (substr( "categoryUNSPSC"::text, 0, 4 ) || \'0000\'::text) as "cat2",
- (substr( "categoryUNSPSC"::text, 0, 6 ) || \'00\'::text) as "cat3",
- "supplierABN","supplierName",
-(
- case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID,
- 
+value,description,category,
+"supplierName",(case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID,
 (\'https://www.tenders.gov.au/?event=public.advancedsearch.keyword&keyword=CN\'::text || "CNID"::text) as sourceURL 
-FROM contractnotice join agency on contractnotice."agencyName"=agency."agencyName"  
+FROM contractnotice join agency_nametoabn on contractnotice."agencyName"=agency_nametoabn."agencyName"  
 where "childCN" is null'
         , array(PDO::ATTR_CURSOR => PDO::FETCH_ORI_NEXT));
-// "supplierCity","supplierPostcode","supplierCountry","contactPostcode",
-// 
 $query->execute();
 $errors = $conn->errorInfo();
 if ($errors[2] != "") {
@@ -57,6 +51,9 @@
                     || $headers[$key] == "contractEnd") {
                 $colvalue = date("Y-m-d", $colvalue);
             }
+           /* if ($headers[$key] == "CNID") {
+                $colvalue = str_replace("A","", $colvalue);
+}*/
             if ($headers[$key] == "cat1" || $headers[$key] == "cat2"
                     || $headers[$key] == "cat3") {
                 $colvalue = $unspsc[$colvalue];