more tables for categories
[contractdashboard.git] / displaySupplier.php
blob:a/displaySupplier.php -> blob:b/displaySupplier.php
<?php <?php
   
include_once ("./lib/common.inc.php"); include_once("./lib/common.inc.php");
if ($_REQUEST['supplier']) { if ($_REQUEST['supplier']) {
$supplierS = htmlentities(strip_tags($_REQUEST['supplier'])); $supplierS = htmlentities(strip_tags($_REQUEST['supplier']));
$title = $supplierName; $title = $supplierName;
if ($supplierABN) { if ($supplierABN) {
$query = 'SELECT text_mode("supplierName") as "supplierName" from contractnotice where "supplierABN" = :supplierABN group by "supplierABN"'; $query = 'SELECT text_mode("supplierName") AS "supplierName" FROM contractnotice WHERE "supplierABN" = :supplierABN GROUP BY "supplierABN"';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->bindParam(":supplierABN", $supplierABN); $query->bindParam(":supplierABN", $supplierABN);
$query->execute(); $query->execute();
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
$title = reset($query->fetchAll())['supplierName']; $title = reset($query->fetchAll())['supplierName'];
} }
include_header(str_replace("%","",$title)); include_header(str_replace("%", "", $title));
echo '<center><h1>'.str_replace("%","",$title).'</h1></center>'; echo '<center><h1>' . str_replace("%", "", $title) . '</h1></center>';
agenciesGraph(); /*
/* * Common names and uncommon names
* Make supplier name the most common name for this ABN * Procurement method in text, seperate Open via SON from Open
* Common names and uncommon names * Consultancies, Confidentialities percentage
* Common categories and uncommon categories */
* Procurement method in text, seperate Open via SON from Open $query = 'SELECT category, min("categoryUNSPSC") AS "categoryUNSPSC", count(*) AS count, sum(value) AS value FROM contractnotice
* Consultancies, Confidentialities percentage WHERE ' . $supplierQ . " " . $standardQ . ' GROUP BY category ORDER BY count(*) DESC LIMIT 10';
*/ $query = $conn->prepare($query);
$query = 'select contractnotice."SONID", min(title) as title, count(*), sum(value) as value from contractnotice inner join standingoffers on contractnotice."SONID" = standingoffers."SONID" WHERE ' .$yearQ . ' ' . if ($supplierParts[0] > 0) {
$supplierQ . ' ' . $standardQ $query->bindParam(":supplierABN", $supplierABN);
. ' and contractnotice."SONID" != \'\' group by contractnotice."SONID"'; } else {
$query = $conn->prepare($query); $query->bindParam(":supplierName", $supplierName);
  }
  $query->execute();
  databaseError($conn->errorInfo());
   
   
if ($supplierParts[0] > 0) { echo "<h3>Categories</h3><table> <thead>
$query->bindParam(":supplierABN", $supplierABN); <tr>
} else { <th>Category</th>
$query->bindParam(":supplierName", $supplierName); <th>Contracts Count</th>
} <th>Total Contract Value</th>
  </tr>
  </thead>";
  foreach ($query->fetchAll() as $row) {
  setlocale(LC_MONETARY, 'en_US');
  $value = number_format(doubleval($row['value']), 2);
  $category = urlencode($row['category']);
  echo("<tr>
  <td><B><a href='displayCategory.php?category=$category'>{$row['category']}</a></b></td>
  <td>{$row['count']}</td>
  <td>\$$value</td>
  </tr>");
  }
  echo "</table><br/>";
   
   
  $query = 'SELECT SUM("value") AS "value", count(*), MAX(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) {
  $query->bindParam(":supplierABN", $supplierABN);
  } else {
  $query->bindParam(":supplierName", $supplierName);
  }
  }
$query->execute(); $query->execute();
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
echo "<h3>Standing Offers/Panels</h3><table> <thead>  
  echo "<h3>Agencies</h3><table> <thead>
  <tr>
  <th>Agency</th>
  <th>Contracts Count</th>
  <th>Total Contract Value</th>
  </tr>
  </thead>";
  foreach ($query->fetchAll() as $row) {
  setlocale(LC_MONETARY, 'en_US');
  $value = number_format(doubleval($row['value']), 2);
  $agency =urlencode($row['agencyname']);
  echo("<tr>
  <td><B><a href=\"displayAgency.php?agency=$agency\">{$row['agencyname']}</a></b></td>
  <td>{$row['count']}</td>
  <td>\$$value</td>
  </tr>");
  }
  echo "</table><br/>";
   
  $query = 'SELECT contractnotice."SONID", min(title) AS title, count(*), sum(value) AS value FROM contractnotice INNER JOIN standingoffers ON contractnotice."SONID" = standingoffers."SONID" WHERE ' . $yearQ . ' ' .
  $supplierQ . ' ' . $standardQ
  . ' AND contractnotice."SONID" != \'\' GROUP BY contractnotice."SONID"';
  $query = $conn->prepare($query);
   
   
  if ($supplierParts[0] > 0) {
  $query->bindParam(":supplierABN", $supplierABN);
  } else {
  $query->bindParam(":supplierName", $supplierName);
  }
  $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> <tr>
<th>Standing Offer</th> <th>Standing Offer</th>
<th>Contracts Count</th> <th>Contracts Count</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
</tr> </tr>
</thead>"; </thead>$sonrows</table><br/>";
foreach ($query->fetchAll() as $row) {  
setlocale(LC_MONETARY, 'en_US');  
$value = number_format(doubleval($row['value']), 2);  
echo ("<tr>  
<td><B><a href=\"displaySON.php?SONID={$row['SONID']}\">{$row['title']}</a></b></td>  
<td>{$row['count']}</td>  
<td>\$$value</td>  
</tr>");  
} }
echo "</table><table><h3>Contracts</h3> <thead> echo "<table><h3>Contracts</h3> <thead>
<tr> <tr>
<th>Contract Notice Number</th> <th>Contract Notice Number</th>
<th>Contract Description</th> <th>Contract Description</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
<th>Agency</th> <th>Agency</th>
<th>Contract Start Date</th> <th>Contract Start Date</th>
<th>Supplier</th> <th>Supplier</th>
</tr> </tr>
</thead>"; </thead>";
$query = 'SELECT "CNID", "description", "value", "agencyName", "category", $query = 'SELECT "CNID", "description", "value", "agencyName", "category",
"contractStart", "supplierName" "contractStart", "supplierName"
FROM contractnotice WHERE ' .$yearQ . ' ' . FROM contractnotice WHERE ' . $yearQ . ' ' .
$supplierQ . ' ' . $standardQ $supplierQ . ' ' . $standardQ
. ' ORDER BY value DESC'; . ' ORDER BY VALUE DESC';
   
$query = $conn->prepare($query); $query = $conn->prepare($query);
   
   
if ($supplierParts[0] > 0) { if ($supplierParts[0] > 0) {
$query->bindParam(":supplierABN", $supplierABN); $query->bindParam(":supplierABN", $supplierABN);
} else { } else {
$query->bindParam(":supplierName", $supplierName); $query->bindParam(":supplierName", $supplierName);
} }
$query->execute(); $query->execute();
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row['value']), 2); $value = number_format(doubleval($row['value']), 2);
echo ("<tr> echo("<tr>
<td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td> <td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td>
<td><b>{$row['description']}</b></a></td> <td><b>{$row['description']}</b></a></td>
<td>\$$value</td><td>{$row['agencyName']}</td> <td>\$$value</td><td>{$row['agencyName']}</td>
<td>{$row['contractStart']}</td> <td>{$row['contractStart']}</td>
<td>{$row['supplierName']}</td> <td>{$row['supplierName']}</td>
</tr>"); </tr>");
} }
echo "</table>"; echo "</table>";
} else { } else {
/* /*
histograph of supplier size/value histograph of supplier size/value
*/ */
include_header("Suppliers"); include_header("Suppliers");
suppliersGraph(); suppliersGraph();
$query = 'SELECT SUM("value") as val, text_mode("supplierName") as supplierName, "supplierABN",( $query = 'SELECT SUM("value") AS val, text_mode("supplierName") AS supplierName, "supplierABN",(
case when "supplierABN" != 0 THEN lower("supplierABN"::text) ELSE lower("supplierName") END) as supplierID CASE WHEN "supplierABN" != 0 THEN lower("supplierABN"::TEXT) ELSE lower("supplierName") END) AS supplierID
FROM contractnotice FROM contractnotice
WHERE ' .$yearQ . ' "childCN" is null WHERE ' . $yearQ . ' "childCN" IS NULL
GROUP BY supplierID,"supplierABN" GROUP BY supplierID,"supplierABN"
ORDER BY val DESC ORDER BY val DESC
LIMIT 100'; LIMIT 100';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
echo "<table> <thead> echo "<table> <thead>
<tr> <tr>
<th>Position</th> <th>Position</th>
<th>Supplier</th> <th>Supplier</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
</tr> </tr>
</thead>"; </thead>";
$i = 1; $i = 1;
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row['val']), 2); $value = number_format(doubleval($row['val']), 2);
$supplier = stripslashes($row['supplierABN'] . '-' . $row['suppliername']); $supplier = stripslashes($row['supplierABN'] . '-' . $row['suppliername']);
echo ("<tr><td>$i</td><td><b><a href=\"displaySupplier.php?supplier={$supplier}\">" . ucsmart($row['suppliername']) . "</a></b></td><td>\$$value</td></tr>\n"); echo("<tr><td>$i</td><td><b><a href=\"displaySupplier.php?supplier={$supplier}\">" . ucsmart($row['suppliername']) . "</a></b></td><td>\$$value</td></tr>\n");
$i++; $i++;
} }
echo "</table>"; echo "</table>";
} }
include_footer(); include_footer();
?> ?>