Better importing CN error display
[contractdashboard.git] / lib / graphs.inc.php
blob:a/lib/graphs.inc.php -> blob:b/lib/graphs.inc.php
--- a/lib/graphs.inc.php
+++ b/lib/graphs.inc.php
@@ -7,6 +7,7 @@
     <script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.js"></script> 
         <script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.pie.js"></script> 
               <script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.selection.js"></script> 
+              <script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.stack.js"></script> 
 
 ';
 $includedFlot = true;
@@ -23,8 +24,9 @@
 	 $(function () {
 
  var d1 = [];
+ var d2 = [];
 <?php
-$query = 'select cnid, count(*) from (select ("CNID" - MOD("CNID",100)) as cnid from contractnotice where "CNID" < 999999) as a group by cnid order by cnid';
+$query = 'select cnid, count(*) from (select ("CNID" - MOD("CNID",100)) as cnid from contractnotice where "CNID" < 999999 and "parentCN" is null) as a group by cnid order by cnid';
 $query = $conn->prepare($query);
 $query->execute();
 if (!$query) {
@@ -35,6 +37,18 @@
 foreach ($query->fetchAll() as $delta) {
 
 	echo "d1.push([ ".intval($delta['cnid']).", ".intval($delta['count'])."]); \n";
+};
+$query = 'select cnid, count(*) from (select ("CNID" - MOD("CNID",100)) as cnid from contractnotice where "CNID" < 999999 and "parentCN" is not null) as a group by cnid order by cnid';
+$query = $conn->prepare($query);
+$query->execute();
+if (!$query) {
+	databaseError($conn->errorInfo());
+	return Array();
+}
+
+foreach ($query->fetchAll() as $delta) {
+
+	echo "d2.push([ ".intval($delta['cnid']).", ".intval($delta['count'])."]); \n";
 };
 ?>
 
@@ -47,10 +61,20 @@
                },
             bars: { show: true }
         },
+       {
+            data: d2,
+series: {
+                   lines: { show: true },
+                   points: { show: true }
+               },
+            bars: { show: true }
+        },
     ];
     var options = 
     {
-
+series: {
+                stack: true,
+            },
             grid: { hoverable: true, clickable: true, labelMargin: 17  },
             selection: { mode: "x" }
     };
@@ -109,7 +133,7 @@
 	
 	global $conn;
 	includeFlot();
-$query = 'SELECT SUM("value") as val, MAX(contractnotice."agencyName") as agencyname FROM contractnotice join agency on contractnotice."agencyName"=agency."agencyName"  WHERE "childCN" = 0
+$query = 'SELECT SUM("value") as val, MAX(contractnotice."agencyName") as agencyname FROM contractnotice join agency on contractnotice."agencyName"=agency."agencyName"  WHERE "childCN" is null
 GROUP BY abn ORDER BY SUM("value") DESC';
 $query = $conn->prepare($query);
 $query->execute();
@@ -167,8 +191,8 @@
 function agencySuppliersGraph($agency) {
 	$agency = "AusAid";
 $topX = 15;
-$query = "SELECT SUM(value) as val, supplierName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND childCN = 0 AND agencyName = '$agency'
-GROUP BY lower(supplierName) ORDER BY val DESC limit $topX";
+$query = 'SELECT SUM(value) as val, supplierName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND "childCN" is null AND agencyName = \'$agency\'
+GROUP BY lower(supplierName) ORDER BY val DESC limit $topX';
 $result = mysql_query($query);
 $suppliers = Array();
 $values = Array();
@@ -178,8 +202,8 @@
 }
 mysql_free_result($result);
 
-$query = "SELECT sum(a.val) as value, count(1) as count from (SELECT SUM(value) as val, supplierName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND childCN = 0 and agencyName = '$agency'
-GROUP BY lower(supplierName) ORDER BY val DESC LIMIT 18446744073709551610 OFFSET $topX) as a";
+$query = 'SELECT sum(a.val) as value, count(1) as count from (SELECT SUM(value) as val, supplierName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND "childCN" is null and agencyName = \'$agency\'
+GROUP BY lower(supplierName) ORDER BY val DESC LIMIT 18446744073709551610 OFFSET $topX) as a';
 $result = mysql_query($query);
 while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
 if ($row['count'] > 0) {
@@ -230,11 +254,11 @@
   "Consultancies",
   "Confidentialities"
 );
-$query = "SELECT 'consultancy', count(1) FROM `contractnotice` WHERE $agencyQ $supplierQ consultancy='Yes' AND childCN = 0;";
+$query = 'SELECT \'consultancy\', count(1) FROM `contractnotice` WHERE $agencyQ $supplierQ consultancy=\'Yes\' AND "childCN" is null;';
 $result = mysql_query($query);
 $row = mysql_fetch_array($result, MYSQL_BOTH);
 $attributes[0] = $row[1];
-$query = "SELECT 'confidentiality', count(1) FROM `contractnotice` WHERE $agencyQ $supplierQ (confidentialityContract='Yes' OR confidentialityOutputs='Yes') AND childCN = 0;";
+$query = 'SELECT \'confidentiality\', count(1) FROM `contractnotice` WHERE $agencyQ $supplierQ (confidentialityContract=\'Yes\' OR confidentialityOutputs=\'Yes\') AND "childCN" is null;';
 $result = mysql_query($query);
 $row = mysql_fetch_array($result, MYSQL_BOTH);
 $attributes[1] = $row[1];
@@ -242,12 +266,12 @@
 	
 }
 function ContractPublishedGraph() {
-	$query = "SELECT YEAR(publishDate), MONTH(publishDate),
+	$query = 'SELECT YEAR(publishDate), MONTH(publishDate),
 SUM(value) as val, count(1) as count FROM `contractnotice`
 WHERE (YEAR(publishDate) >= 2008)
-AND childCN = 0
+AND "childCN" is null
 GROUP BY MONTH(publishDate), YEAR(publishDate) 
-ORDER BY YEAR(publishDate), MONTH(publishDate)";
+ORDER BY YEAR(publishDate), MONTH(publishDate)';
 
 $result = mysql_query($query);
 $dates = Array();
@@ -264,12 +288,12 @@
 
 }
 function ContractStartingGraph() {
-	$query = "SELECT YEAR(contractStart), MONTH(contractStart),
+	$query = 'SELECT YEAR(contractStart), MONTH(contractStart),
 SUM(value) as val, count(1) as count FROM `contractnotice`
 WHERE (YEAR(contractStart) >= 2008)
-AND childCN = 0
+AND "childCN" is null
 GROUP BY MONTH(contractStart), YEAR(contractStart) 
-ORDER BY YEAR(contractStart), MONTH(contractStart)";
+ORDER BY YEAR(contractStart), MONTH(contractStart)';
 
 $result = mysql_query($query);
 $dates = Array();
@@ -285,8 +309,8 @@
 mysql_free_result($result);
 }
 function MethodCountGraph() {
-	$query = "select procurementMethod, count(1) as count, SUM(value) as value, MONTH(contractStart) as month, YEAR(contractStart) as year from `contractnotice`
-where $agencyQ $supplierQ $standardQ group by procurementMethod,year,month order by procurementMethod,year,month";
+	$query = 'select procurementMethod, count(1) as count, SUM(value) as value, MONTH(contractStart) as month, YEAR(contractStart) as year from `contractnotice`
+where $agencyQ $supplierQ $standardQ group by procurementMethod,year,month order by procurementMethod,year,month';
 $result = mysql_query($query);
 $methods = Array("Direct","Open","Select");
 $dates = Array();
@@ -357,7 +381,7 @@
 $query = 'SELECT SUM("value") as value, MAX("supplierName") as supplierName, (
  case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID 
 FROM contractnotice
-WHERE "childCN" = 0
+WHERE "childCN" is null
 GROUP BY supplierID
 ORDER BY value DESC
 LIMIT '.$topX;
@@ -374,7 +398,7 @@
 }
 
 $query = 'SELECT sum(a.svalue) as val, suppliercountry from (SELECT sum("value") as svalue,  max("supplierCountry") as suppliercountry
-FROM contractnotice WHERE "childCN" = 0 and "supplierCountry" NOT ILIKE \'Australia\'
+FROM contractnotice WHERE "childCN" is null and "supplierCountry" NOT ILIKE \'Australia\'
 GROUP BY "supplierName" ORDER BY svalue LIMIT 18446744073 OFFSET 10) as a group by suppliercountry order by val DESC limit 10 ';
 $query = $conn->prepare($query);
   $query->execute();
@@ -390,7 +414,7 @@
 
 $query = 'SELECT sum(a.value) as val, substring(
 supplierpostcode from 0 for 2) as postcode from (SELECT sum(value) as value, max("supplierPostcode") as supplierpostcode, max("supplierCountry") as suppliercountry
-FROM contractnotice WHERE "childCN" = 0 
+FROM contractnotice WHERE "childCN" is null 
 GROUP BY "supplierABN" ORDER BY sum(value) LIMIT 1844674 OFFSET 10) as a
 WHERE (suppliercountry ILIKE \'Australia\')
 group by substring(