new stats box
new stats box

<?php <?php
if (php_sapi_name() != "cli") { if (php_sapi_name() != "cli") {
include_once ("../lib/common.inc.php"); include_once ("../lib/common.inc.php");
//auth(); //auth();
$contractNoticeFields = array( $contractNoticeFields = array(
"importFile", "importFile",
"agencyName", "agencyName",
"parentCN", "parentCN",
"CNID", "CNID",
"publishDate", "publishDate",
"amendDate", "amendDate",
"contractStart", "contractStart",
"contractEnd", "contractEnd",
"value", "value",
"description", "description",
"agencyID", "agencyID",
"category", "category",
"procurementMethod", "procurementMethod",
"atmID", "atmID",
"SONID", "SONID",
"confidentialityContract", "confidentialityContract",
"confidentialityContractReason", "confidentialityContractReason",
"confidentialityOutputs", "confidentialityOutputs",
"confidentialityOutputsReason", "confidentialityOutputsReason",
"consultancy", "consultancy",
"consultancyReason", "consultancyReason",
"amendmentReason", "amendmentReason",
"supplierName", "supplierName",
"supplierAddress", "supplierAddress",
"supplierCity", "supplierCity",
"supplierPostcode", "supplierPostcode",
"supplierCountry", "supplierCountry",
"supplierABNExempt", "supplierABNExempt",
"supplierABN", "supplierABN",
"contactBranch", "contactBranch",
"contactDivision", "contactDivision",
"contactPostcode" "contactPostcode"
); );
   
$contractNoticeInsertQ = 'INSERT INTO contractnotice ("' . implode('" , "', $contractNoticeFields) . '") VALUES ( '; $contractNoticeInsertQ = 'INSERT INTO contractnotice ("' . implode('" , "', $contractNoticeFields) . '") VALUES ( ';
foreach ($contractNoticeFields as $key => $f) { foreach ($contractNoticeFields as $key => $f) {
$contractNoticeInsertQ.= ($key == 0 ? "" : ", ") . "?"; $contractNoticeInsertQ.= ($key == 0 ? "" : ", ") . "?";
} }
$contractNoticeInsertQ.= ");"; $contractNoticeInsertQ.= ");";
$contractNoticeInsertQ = $conn->prepare($contractNoticeInsertQ); $contractNoticeInsertQ = $conn->prepare($contractNoticeInsertQ);
function processFile($fpath) { function processFile($fpath) {
global $conn, $contractNoticeFields, $contractNoticeInsertQ; global $conn, $contractNoticeFields, $contractNoticeInsertQ;
$success = 0; $success = 0;
$row = 1; $row = 1;
$handle = fopen($fpath, "r"); $handle = fopen($fpath, "r");
//"t" mode string translates windows line breaks to unix //"t" mode string translates windows line breaks to unix
//On the 15 April 2014 AusTender Contract Notice functionality changed to improve transparency. Two new fields have been introduced to capture the ‘Amendment Value’ and the ‘Amendment Start Date’. Where applicable, these fields will display on amendment records published after this date. //On the 15 April 2014 AusTender Contract Notice functionality changed to improve transparency. Two new fields have been introduced to capture the ‘Amendment Value’ and the ‘Amendment Start Date’. Where applicable, these fields will display on amendment records published after this date.
$datamapping0712 = array( $datamapping0712 = array(
"Agency" => "agencyName", "Agency" => "agencyName",
"Parent CN ID" => "parentCN", "Parent CN ID" => "parentCN",
"CN ID" => "CNID", "CN ID" => "CNID",
"Publish Date" => "publishDate", "Publish Date" => "publishDate",
"Amendment Date" => "amendDate", "Amendment Date" => "amendDate",
"Amendment Publish Date" => "amendDate", "Amendment Publish Date" => "amendDate",
"Status" => "", "Status" => "",
"StartDate" => "contractStart", "StartDate" => "contractStart",
"EndDate" => "contractEnd", "EndDate" => "contractEnd",
"Value" => "value", "Value" => "value",
"Description" => "description", "Description" => "description",
"Agency Ref Id" => "agencyID", "Agency Ref Id" => "agencyID",
"Agency Ref. ID" => "agencyID", "Agency Ref. ID" => "agencyID",
"Category" => "category", "Category" => "category",
"Procurement Method" => "procurementMethod", "Procurement Method" => "procurementMethod",
"ATM ID" => "atmID", "ATM ID" => "atmID",
"SON ID" => "SONID", "SON ID" => "SONID",
"Confidentiality - Contract" => "confidentialityContract", "Confidentiality - Contract" => "confidentialityContract",
"Confidentiality - Contract Reason(s)" => "confidentialityContractReason", "Confidentiality - Contract Reason(s)" => "confidentialityContractReason",
"Confidentiality - Outputs" => "confidentialityOutputs", "Confidentiality - Outputs" => "confidentialityOutputs",
"Confidentiality - Outputs Reason(s)" => "confidentialityOutputsReason", "Confidentiality - Outputs Reason(s)" => "confidentialityOutputsReason",
"Consultancy" => "consultancy", "Consultancy" => "consultancy",
"Consultancy Reason(s)" => "consultancyReason", "Consultancy Reason(s)" => "consultancyReason",
"Amendment Reason" => "amendmentReason", "Amendment Reason" => "amendmentReason",
"Supplier Name" => "supplierName", "Supplier Name" => "supplierName",
"Supplier Address" => "supplierAddress", "Supplier Address" => "supplierAddress",
"Supplier City" => "supplierCity", "Supplier City" => "supplierCity",
"Supplier Postcode" => "supplierPostcode", "Supplier Postcode" => "supplierPostcode",
"Supplier Country" => "supplierCountry", "Supplier Country" => "supplierCountry",
"Supplier ABNExempt" => "supplierABNExempt", "Supplier ABNExempt" => "supplierABNExempt",
"Supplier ABN" => "supplierABN", "Supplier ABN" => "supplierABN",
"Agency Branch" => "contactBranch", "Agency Branch" => "contactBranch",
"Agency Divison" => "contactDivision", "Agency Divison" => "contactDivision",
"Agency Postcode" => "contactPostcode", "Agency Postcode" => "contactPostcode",
"" => "" "" => ""
); );
   
   
while (($data = fgetcsv($handle, 1200, "\t")) !== false) { while (($data = fgetcsv($handle, 1200, "\t")) !== false) {
$num = count($data); $num = count($data);
if ($row == 3) { if ($row == 3) {
$headers = $data; $headers = $data;
} elseif ($row > 3) { } elseif ($row > 3) {
if ($num > count($datamapping0712)) { if ($num > count($datamapping0712)) {
die("<font color=red>Error in data import; data mapping fields out of bounds or changed</font><br>" . $fname . print_r($data)); die("<font color=red>Error in data import; data mapping fields out of bounds or changed</font><br>" . $fname . print_r($data));
} }
$contractNoticeInsert = Array(); $contractNoticeInsert = Array();
$supplierInsert = Array(); $supplierInsert = Array();
$agencyInsert = Array(); $agencyInsert = Array();
$contractNoticeInsert[] = $fpath; $contractNoticeInsert[] = $fpath;
$keys = array_keys($datamapping0712); $keys = array_keys($datamapping0712);
for ($c = 0; $c < $num; $c++) { for ($c = 0; $c < $num; $c++) {
$data[$c] = trim($data[$c], "="); $data[$c] = trim($data[$c], "=");
$data[$c] = trim($data[$c], "\""); $data[$c] = trim($data[$c], "\"");
if (in_array(($datamapping0712[$headers[$c]]), $contractNoticeFields)) { if (in_array(($datamapping0712[$headers[$c]]), $contractNoticeFields)) {
if (($datamapping0712[$headers[$c]]) == "parentCN" || ($datamapping0712[$headers[$c]]) == "CNID") { if (($datamapping0712[$headers[$c]]) == "parentCN" || ($datamapping0712[$headers[$c]]) == "CNID") {
$data[$c] = substr($data[$c], 2); // take off the "CN" prefix $data[$c] = substr($data[$c], 2); // take off the "CN" prefix
if ($data[$c] > 0 && $data[$c] != '0') { if ($data[$c] > 0 && $data[$c] != '0' && $data[$c] != '') {
$contractNoticeInsert[] = $data[$c]; $contractNoticeInsert[] = $data[$c];
} else { } else {
$contractNoticeInsert[] = null; $contractNoticeInsert[] = null;
} }
} elseif (($datamapping0712[$headers[$c]]) == "supplierABN") { } elseif (($datamapping0712[$headers[$c]]) == "supplierABN" || ($datamapping0712[$headers[$c]]) == "SONID") {
if ($data[$c] > 0 && $data[$c] != '0') { if ($data[$c] > 0 && $data[$c] != '0' && $data[$c] != '') {
$contractNoticeInsert[] = $data[$c]; $contractNoticeInsert[] = $data[$c];
} else { } else {
$contractNoticeInsert[] = null; $contractNoticeInsert[] = null;
} }
} elseif (($datamapping0712[$headers[$c]]) == "amendDate" || ($datamapping0712[$headers[$c]]) == "publishDate" || ($datamapping0712[$headers[$c]]) == "contractStart" || ($datamapping0712[$headers[$c]]) == "contractEnd") { } elseif (($datamapping0712[$headers[$c]]) == "amendDate" || ($datamapping0712[$headers[$c]]) == "publishDate" || ($datamapping0712[$headers[$c]]) == "contractStart" || ($datamapping0712[$headers[$c]]) == "contractEnd") {
$contractNoticeInsert[] = date('Y-m-d H:i:s', strtotime($data[$c])); $contractNoticeInsert[] = date('Y-m-d H:i:s', strtotime($data[$c]));
} else { } else {
if (strstr("\" =", $data[$c] > 0)) { if (strstr("\" =", $data[$c] > 0)) {
die("Invalid Description field" . $contractNoticeInsert); die("Invalid Description field" . $contractNoticeInsert);
} }
$colvalue = preg_replace('/[^[:print:]]/', '', utf8_encode($data[$c])); $colvalue = preg_replace('/[^[:print:]]/', '', utf8_encode($data[$c]));
   
$contractNoticeInsert[] = $colvalue; $contractNoticeInsert[] = $colvalue;
} }
} }
} }
flush(); flush();
$contractNoticeInsertQ->execute($contractNoticeInsert); $contractNoticeInsertQ->execute($contractNoticeInsert);
$errors = $conn->errorInfo(); $errors = $conn->errorInfo();
if ($errors[1] == 7 && strpos($errors[2], "duplicate key")) { if ($errors[1] == 7 && strpos($errors[2], "duplicate key")) {
} elseif ($errors[1] <= 0) { } elseif ($errors[1] <= 0) {
//print_r($errors); //print_r($errors);
$success = 1; $success = 1;
} else { } else {
foreach ($contractNoticeFields as $key => $cnf) { foreach ($contractNoticeFields as $key => $cnf) {
echo var_dump($contractNoticeInsert[$key]) . $cnf . "<br>"; echo var_dump($contractNoticeInsert[$key]) . $cnf . "<br>";
} }
echo $data[2] . " failed CN insert.<br>" . print_r($errors, true) . "<br> row $row <br><br>\n"; echo $data[2] . " failed CN insert.<br>" . print_r($errors, true) . "<br> row $row <br><br>\n";
} }
   
flush(); flush();
//echo "<hr>\n"; //echo "<hr>\n";
} }
$row++; $row++;
} }
fclose($handle); fclose($handle);
$contractNoticeInsertQ->closeCursor(); $contractNoticeInsertQ->closeCursor();
   
return $success; return $success;
} }
   
$path = 'data/'; $path = 'data/';
if ($_REQUEST["fname"] == "") { if ($_REQUEST["fname"] == "") {
echo "Get files from: https://www.tenders.gov.au/?event=public.reports.list<br>"; echo "Get files from: https://www.tenders.gov.au/?event=public.reports.list<br>";
$dhandle = opendir($path); $dhandle = opendir($path);
// define an array to hold the files // define an array to hold the files
$files = array(); $files = array();
if ($dhandle) { if ($dhandle) {
// loop through all of the files // loop through all of the files
while (false !== ($fname = readdir($dhandle))) { while (false !== ($fname = readdir($dhandle))) {
if (($fname != '.') && ($fname != '..')) { if (($fname != '.') && ($fname != '..')) {
$files[date("c", filemtime($path . $fname)) . md5($fname)] = $fname; $files[date("c", filemtime($path . $fname)) . md5($fname)] = $fname;
} }
} }
} }
ksort($files); ksort($files);
foreach ($files as $date => $fname) { foreach ($files as $date => $fname) {
echo "<a href=\"import.php?fname=$fname\">$fname</a>&nbsp;" . filesize($path . $fname) . "&nbsp;" . $date . "<br/>"; echo "<a href=\"import.php?fname=$fname\">$fname</a>&nbsp;" . filesize($path . $fname) . "&nbsp;" . $date . "<br/>";
} }
} else { } else {
$success = 0; $success = 0;
$fname = $_REQUEST["fname"]; $fname = $_REQUEST["fname"];
echo " ============== $fname ============== <br>"; echo " ============== $fname ============== <br>";
flush(); flush();
$success+= processFile($path . $fname, "contractnotice"); $success+= processFile($path . $fname, "contractnotice");
$success+= processFile($path . $fname, "agency"); $success+= processFile($path . $fname, "agency");
$success+= processFile($path . $fname, "supplier"); $success+= processFile($path . $fname, "supplier");
echo "<br> $success records successfully created"; echo "<br> $success records successfully created";
   
flush(); flush();
// run post import data processing // run post import data processing
// //
if ($success > 0) { if ($success > 0) {
$conn->exec("update datasets set \"lastUpdated\" = NOW() where title = 'Contract Notices'"); $conn->exec("update datasets set \"lastUpdated\" = NOW() where title = 'Contract Notices'");
/* echo "link amend<br>"; echo "link amend<br>";
include ("linkAmendments.php"); include ("linkAmendments.php");
echo "update UNSPSC<br>"; echo "update UNSPSC<br>";
include ("updateUNSPSC.php");*/ include ("updateUNSPSC.php");
} }
// cn // cn
   
// agency // agency
//include ("setAgencyStatus.php"); //include ("setAgencyStatus.php");
//include ("setAgencyURLABN.php"); //include ("setAgencyURLABN.php");
} }
} }
?> ?>
   
<?php <?php
   
include_once ("../lib/common.inc.php"); include_once ("../lib/common.inc.php");
auth();  
/* todo gaps /* todo gaps
Contract ID,Department,Portfolio,Division,Branch,Agency Ref,Contract Date,End Date,Value,Office PCode,Description,Procurement Desc,Confidentiality Reason,Consultancy,ANZSCC Code,ANSCC Desc,Supplier,Supplier Postal Addr,Supplier Suburb,Supplier State,Supplier Country,Supplier PCode,Supplier ABN,Supplier DUNS,Supplier ACN,S/O Reference Num Contract ID,Department,Portfolio,Division,Branch,Agency Ref,Contract Date,End Date,Value,Office PCode,Description,Procurement Desc,Confidentiality Reason,Consultancy,ANZSCC Code,ANSCC Desc,Supplier,Supplier Postal Addr,Supplier Suburb,Supplier State,Supplier Country,Supplier PCode,Supplier ABN,Supplier DUNS,Supplier ACN,S/O Reference Num
1694570,Department of Defence,Defence,NEW SOUTH WALES,RAN HMAS WATSON,1906458734 ,30-Jun-2007,30-Jun-2007,16083.96,2612,AIRLINE TICKETS,direct source,,No,731,Passenger transportation by air,QANTAS AIRWAYS LTD,PO Box PB 747,MASCOT,NSW,Australia,2020,16009661901,750512642,009661901 , 1694570,Department of Defence,Defence,NEW SOUTH WALES,RAN HMAS WATSON,1906458734 ,30-Jun-2007,30-Jun-2007,16083.96,2612,AIRLINE TICKETS,direct source,,No,731,Passenger transportation by air,QANTAS AIRWAYS LTD,PO Box PB 747,MASCOT,NSW,Australia,2020,16009661901,750512642,009661901 ,
   
*/ */
$contractNoticeFields = array( $contractNoticeFields = array(
"importFile", "importFile",
"agencyName", "agencyName",
"parentCN", "parentCN",
"CNID", "CNID",
"publishDate", "publishDate",
"amendDate", "amendDate",
"contractStart", "contractStart",
"contractEnd", "contractEnd",
"value", "value",
"description", "description",
"agencyID", "agencyID",
"categoryUNSPSC", "categoryUNSPSC",
"category", "category",
"procurementMethod", "procurementMethod",
"atmID", "atmID",
"SONID", "SONID",
  "SONPanelArrangement",
"confidentialityContract", "confidentialityContract",
"confidentialityContractReason", "confidentialityContractReason",
"confidentialityOutputs", "confidentialityOutputs",
"confidentialityOutputsReason", "confidentialityOutputsReason",
"consultancy", "consultancy",
"consultancyReason", "consultancyReason",
"amendmentReason", "amendmentReason",
"supplierName", "supplierName",
"supplierAddress", "supplierAddress",
"supplierCity", "supplierCity",
"supplierPostcode", "supplierPostcode",
"supplierCountry", "supplierCountry",
"supplierABNExempt", "supplierABNExempt",
"supplierABN", "supplierABN",
"contactBranch", "contactBranch",
"contactDivision", "contactDivision",
"contactPostcode" "contactPostcode"
); );
   
$contractNoticeInsertQ = 'INSERT INTO contractnotice ("' . implode('" , "', $contractNoticeFields) . '") VALUES ( '; $contractNoticeInsertQ = 'INSERT INTO contractnotice ("' . implode('" , "', $contractNoticeFields) . '") VALUES ( ';
foreach ($contractNoticeFields as $key => $f) { foreach ($contractNoticeFields as $key => $f) {
$contractNoticeInsertQ.= ($key == 0 ? "" : ", ") . "?"; $contractNoticeInsertQ.= ($key == 0 ? "" : ", ") . "?";
} }
$contractNoticeInsertQ.= ");"; $contractNoticeInsertQ.= ");";
$contractNoticeInsertQ = $conn->prepare($contractNoticeInsertQ); $contractNoticeInsertQ = $conn->prepare($contractNoticeInsertQ);
   
  $contractNoticeUpdateQ = 'UPDATE contractnotice SET ("' . implode('" , "', $contractNoticeFields) . '") = ( ';
  foreach ($contractNoticeFields as $key => $f) {
  $contractNoticeUpdateQ.= ($key == 0 ? "" : ", ") . "?";
  }
  $contractNoticeUpdateQ.= ') where "CNID" = ?;';
  $contractNoticeUpdateQ = $conn->prepare($contractNoticeUpdateQ);
   
function processFile($fpath) { function processFile($fpath) {
global $conn, $contractNoticeFields, $contractNoticeInsertQ; global $conn, $contractNoticeFields, $contractNoticeInsertQ, $contractNoticeUpdateQ;
$row = 1; $row = 1;
$success = 0; $success = 0;
ini_set('auto_detect_line_endings',TRUE); ini_set('auto_detect_line_endings',TRUE);
$handle = fopen($fpath, "r"); $handle = fopen($fpath, "r");
//"t" mode string translates windows line breaks to unix //"t" mode string translates windows line breaks to unix
$datamapping0712 = array( $datamapping0712 = array(
   
// "_id" => "", // "_id" => "",
"Agency Name" => "agencyName", "Agency Name" => "agencyName",
"Parent Contract ID" => "parentCN", "Parent Contract ID" => "parentCN",
"Contract ID" => "CNID", "Contract ID" => "CNID",
"Publish Date" => "publishDate", "Publish Date" => "publishDate",
"AmendmentDate" => "amendDate", "Amendment Date" => "amendDate",
"Start Date" => "contractStart", "Start Date" => "contractStart",
"End Date" => "contractEnd", "End Date" => "contractEnd",
"Value" => "value", "Value" => "value",
"Description" => "description", "Description" => "description",
"Agency Ref ID" => "agencyID", "Agency Ref ID" => "agencyID",
"UNSPSC Code" => "categoryUNSPSC", "UNSPSC Code" => "categoryUNSPSC",
"Title" => "category", "UNSPSC Title" => "category",
"Procurement Method" => "procurementMethod", "Procurement Method" => "procurementMethod",
"TenderNumber" => "atmID", "ATM ID" => "atmID",
"SON ID" => "SONID", "SON ID" => "SONID",
  "Panel Arrangement" => "SONPanelArrangement",
"Confidentiality Contract Flag" => "confidentialityContract", "Confidentiality Contract Flag" => "confidentialityContract",
"Confidentiality Contract Reason" => "confidentialityContractReason", "Confidentiality Contract Reason" => "confidentialityContractReason",
"Confidentiality Outputs Flag" => "confidentialityOutputs", "Confidentiality Outputs Flag" => "confidentialityOutputs",
"Confidentiality Outputs Reason" => "confidentialityOutputsReason", "Confidentiality Outputs Reason" => "confidentialityOutputsReason",
"Consultancy Flag" => "consultancy", "Consultancy Flag" => "consultancy",
"Consultancy Reason" => "consultancyReason", "Consultancy Reason" => "consultancyReason",
"Amendment Reason" => "amendmentReason", "Amendment Reason" => "amendmentReason",
"Supplier Name" => "supplierName", "Supplier Name" => "supplierName",
"SupplierAddress" => "supplierAddress", "Supplier Address" => "supplierAddress",
"SupplierSuburb" => "supplierCity", "Supplier Suburb" => "supplierCity",
"Supplier Postcode" => "supplierPostcode", "Supplier Postcode" => "supplierPostcode",
"Supplier Country" => "supplierCountry", "Supplier Country" => "supplierCountry",
"Supplier ABN Exempt" => "supplierABNExempt", "Supplier ABN Exempt" => "supplierABNExempt",
"ABN" => "supplierABN", "Supplier ABN" => "supplierABN",
"Contact Name" => "", "Contact Name" => "",
"Contact Phone" => "", "Contact Phone" => "",
"Branch" => "contactBranch", "Branch" => "contactBranch",
"Division" => "contactDivision", "Division" => "contactDivision",
"Office Postcode" => "contactPostcode", "Office Postcode" => "contactPostcode",
   
); );
   
   
while (($data = fgetcsv($handle, 10000)) !== false) { while (($data = fgetcsv($handle, 10000)) !== false) {
//print_r($data); //print_r($data);
$num = count($data); $num = count($data);
if ($row == 1) { if ($row == 1) {
$headers = $data; $headers = $data;
} elseif ($row > 1) { } elseif ($row >30000 && $row < 59000) {
if ($num > count($datamapping0712)) { if ($num > count($datamapping0712)) {
die("<font color=red>Error in data import; data mapping fields out of bounds or changed $num > ".count($datamapping0712)."</font><br>" . $fpath . print_r($data)); die("<font color=red>Error in data import; data mapping fields out of bounds or changed $num > ".count($datamapping0712)."</font><br>" . $fpath . print_r($data));
} }
$contractNoticeInsert = Array(); $contractNoticeInsert = Array();
$supplierInsert = Array(); $supplierInsert = Array();
$agencyInsert = Array(); $agencyInsert = Array();
$contractNoticeInsert[] = $fpath; $contractNoticeInsert[] = $fpath;
$keys = array_keys($datamapping0712); $keys = array_keys($datamapping0712);
for ($c = 0; $c < $num; $c++) { for ($c = 0; $c < $num; $c++) {
$data[$c] = trim($data[$c], "="); $data[$c] = trim($data[$c], "=");
$data[$c] = trim($data[$c], "\""); $data[$c] = trim($data[$c], "\"");
if (in_array(($datamapping0712[$headers[$c]]), $contractNoticeFields)) { if (in_array(($datamapping0712[$headers[$c]]), $contractNoticeFields)) {
if (($datamapping0712[$headers[$c]]) == "parentCN" || ($datamapping0712[$headers[$c]]) == "CNID") { if (($datamapping0712[$headers[$c]]) == "parentCN" || ($datamapping0712[$headers[$c]]) == "CNID") {
$data[$c] = substr($data[$c], 2); // take off the "CN" prefix $data[$c] = substr($data[$c], 2); // take off the "CN" prefix
if ($data[$c] > 0 && $data[$c] != '0') { if ($data[$c] > 0 && $data[$c] != '0') {
$contractNoticeInsert[] = $data[$c]; $contractNoticeInsert[] = $data[$c];
} else { } else {
$contractNoticeInsert[] = null; $contractNoticeInsert[] = null;
} }
} elseif (($datamapping0712[$headers[$c]]) == "supplierABN") { } elseif (($datamapping0712[$headers[$c]]) == "supplierABN") {
if ($data[$c] > 0 && $data[$c] != '0') { if ($data[$c] > 0 && $data[$c] != '0') {
$contractNoticeInsert[] = $data[$c]; $contractNoticeInsert[] = $data[$c];
} else { } else {
$contractNoticeInsert[] = null; $contractNoticeInsert[] = null;
} }
} elseif (($datamapping0712[$headers[$c]]) == "amendDate" || ($datamapping0712[$headers[$c]]) == "publishDate" || ($datamapping0712[$headers[$c]]) == "contractStart" || ($datamapping0712[$headers[$c]]) == "contractEnd") { } elseif (($datamapping0712[$headers[$c]]) == "amendDate" || ($datamapping0712[$headers[$c]]) == "publishDate" || ($datamapping0712[$headers[$c]]) == "contractStart" || ($datamapping0712[$headers[$c]]) == "contractEnd") {
//echo $datamapping0712[$headers[$c]]." ".$data[$c]." ".date('Y-m-d H:i:s', strtotime(str_replace('/','-',$data[$c])))."\n"; //echo $datamapping0712[$headers[$c]]." ".$data[$c]." ".date('Y-m-d H:i:s', strtotime(str_replace('/','-',$data[$c])))."\n";
$contractNoticeInsert[] = date('Y-m-d H:i:s', strtotime(str_replace('/','-',$data[$c]))); $contractNoticeInsert[] = date('Y-m-d H:i:s', strtotime(str_replace('/','-',$data[$c])));
} else { } else {
if (strstr("\" =", $data[$c] > 0)) { if (strstr("\" =", $data[$c] > 0)) {
die("Invalid Description field" . $contractNoticeInsert); die("Invalid Description field" . $contractNoticeInsert);
} }
$colvalue = preg_replace('/[^[:print:]]/', '', utf8_encode($data[$c])); $colvalue = preg_replace('/[^[:print:]]/', '', utf8_encode($data[$c]));
   
$contractNoticeInsert[] = $colvalue; $contractNoticeInsert[] = $colvalue;
} }
} }
} }
flush(); flush();
// print_r($contractNoticeInsert); // print_r($contractNoticeInsert);
$contractNoticeInsertQ->execute($contractNoticeInsert); /* $contractNoticeInsertQ->execute($contractNoticeInsert);
$errors = $conn->errorInfo(); $errors = $conn->errorInfo();
if ($errors[1] == 7 && strpos($errors[2], "duplicate key")) { if ($errors[1] == 7 && strpos($errors[2], "duplicate key")) {
// echo "dupe {$data[2]} row $row <br>\n"; echo "dupe {$data[2]} row $row <br>\n";
} else { } else {
if ($errors[1] == 0) { if ($errors[1] == 0) {
echo "success {$data[2]} row $row <br>\n"; echo "success insert {$data[2]} row $row <br>\n";
$success++; $success++;
} else { } else {
foreach ($contractNoticeFields as $key => $cnf) { foreach ($contractNoticeFields as $key => $cnf) {
echo var_dump($contractNoticeInsert[$key]) . $cnf . "<br>"; echo var_dump($contractNoticeInsert[$key]) . $cnf . "<br>";
} }
echo $data[2] . " failed CN insert.<br>" . print_r($errors, true) . "<br> row $row <br><br>\n"; echo $data[2] . " failed CN insert.<br>" . print_r($errors, true) . "<br> row $row <br><br>\n";
} }
} }*/
   
   
  $contractNoticeUpdate = $contractNoticeInsert;
  $contractNoticeUpdate[] = $data[2];
  #var_dump($contractNoticeUpdate);
  /*$i =0;
  while($i < 35) {
  echo "{$contractNoticeFields[$i]} : {$contractNoticeUpdate[$i]}<br/>";
  $i++;
  }*/
  $contractNoticeUpdateQ->execute($contractNoticeUpdate);
  $errors = $conn->errorInfo();
   
  if ($errors[1] == 0) {
  // echo "success update {$data[2]} row $row <br>\n";
  $success++;
  } else {
  foreach ($contractNoticeFields as $key => $cnf) {
  echo var_dump($contractNoticeUpdate[$key]) . $cnf . "<br>";
  }
  echo $data[2] . " failed CN update.<br>" . print_r($errors, true) . "<br> row $row <br><br>\n";
  }
   
flush(); flush();
  //die('endlol');
//echo "<hr>\n"; //echo "<hr>\n";
} }
$row++; $row++;
} }
fclose($handle); fclose($handle);
$contractNoticeInsertQ->closeCursor(); $contractNoticeInsertQ->closeCursor();
   
return $success; return $success;
} }
   
$path = 'datagovdata/'; $path = 'datagovdata/';
if ($_REQUEST["fname"] == "" && $argv[1] == "") { if ($_REQUEST["fname"] == "" && $argv[1] == "") {
echo "Get files from: https://www.tenders.gov.au/?event=public.reports.list<br>"; echo "Get files from: https://www.tenders.gov.au/?event=public.reports.list<br>";
$dhandle = opendir($path); $dhandle = opendir($path);
// define an array to hold the files // define an array to hold the files
$files = array(); $files = array();
if ($dhandle) { if ($dhandle) {
// loop through all of the files // loop through all of the files
while (false !== ($fname = readdir($dhandle))) { while (false !== ($fname = readdir($dhandle))) {
if (($fname != '.') && ($fname != '..')) { if (($fname != '.') && ($fname != '..')) {
$files[date("c", filemtime($path . $fname)) . md5($fname)] = $fname; $files[date("c", filemtime($path . $fname)) . md5($fname)] = $fname;
} }
} }
} }
ksort($files); ksort($files);
foreach ($files as $date => $fname) { foreach ($files as $date => $fname) {
echo "<a href=\"importdatagov.php?fname=$fname\">$fname</a>&nbsp;" . filesize($path . $fname) . "&nbsp;" . $date . "<br/>"; echo "<a href=\"importdatagov.php?fname=$fname\">$fname</a>&nbsp;" . filesize($path . $fname) . "&nbsp;" . $date . "<br/>";
} }
} else { } else {
$success = 0; $success = 0;
$fname = $_REQUEST["fname"]; $fname = $_REQUEST["fname"];
if ($argv[1] != "") $fname = $argv[1]; if ($argv[1] != "") $fname = $argv[1];
echo " ============== $fname ============== <br>"; echo " ============== $fname ============== <br>";
flush(); flush();
$success+= processFile($path . $fname, "contractnotice"); $success+= processFile($path . $fname, "contractnotice");
$success+= processFile($path . $fname, "agency"); $success+= processFile($path . $fname, "agency");
$success+= processFile($path . $fname, "supplier"); $success+= processFile($path . $fname, "supplier");
echo "<br> $success records successfully created"; echo "<br> $success records successfully created";
   
flush(); flush();
// run post import data processing // run post import data processing
// //
if ($success > 0) { if ($success > 0) {
$conn->exec("update datasets set \"lastUpdated\" = NOW() where title = 'Contract Notices'"); $conn->exec("update datasets set \"lastUpdated\" = NOW() where title = 'Contract Notices'");
echo "link amend<br>"; /*echo "link amend<br>";
include ("linkAmendments.php"); include ("linkAmendments.php");
echo "update UNSPSC<br>"; echo "update UNSPSC<br>";
include ("updateUNSPSC.php"); include ("updateUNSPSC.php");*/
} }
// cn // cn
   
// agency // agency
//include ("setAgencyStatus.php"); //include ("setAgencyStatus.php");
//include ("setAgencyURLABN.php"); //include ("setAgencyURLABN.php");
   
} }
?> ?>
   
<?php <?php
include_once ("../lib/common.inc.php"); include_once ("../lib/common.inc.php");
if (php_sapi_name() != "cli") {  
   
//auth();  
}  
$query = 'update contractnotice set "parentCN" = null where "parentCN" = \'0\''; $query = 'update contractnotice set "parentCN" = null where "parentCN" = \'0\'';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
$query = 'update contractnotice set "supplierABN" = null where "supplierABN" = \'0\''; $query = 'update contractnotice set "supplierABN" = null where "supplierABN" = \'0\'';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
$query = 'SELECT c."CNID",c."parentCN",p."childCN" FROM contractnotice as c LEFT OUTER JOIN contractnotice as p on c."parentCN" = p."CNID" $query = 'SELECT c."CNID",c."parentCN",p."childCN" FROM contractnotice as c LEFT OUTER JOIN contractnotice as p on c."parentCN" = p."CNID"
WHERE WHERE
c."parentCN" IS NOT NULL AND p."childCN" IS NULL '; c."parentCN" IS NOT NULL AND p."childCN" IS NULL ';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
if ($row['parentCN'] != 0) { if ($row['parentCN'] != 0) {
$conn->exec('UPDATE contractnotice SET "childCN" = \'' . $conn->exec('UPDATE contractnotice SET "childCN" = \'' .
$row['CNID'] . '\' where "CNID" = \'' . $row['CNID'] . '\' where "CNID" = \'' .
$row['parentCN'] . '\';'); $row['parentCN'] . '\';');
echo 'UPDATE contractnotice SET "childCN" = \'' . echo 'UPDATE contractnotice SET "childCN" = \'' .
$row['CNID'] . '\' where "CNID" = \'' . $row['CNID'] . '\' where "CNID" = \'' .
$row['parentCN'] . '\';'; $row['parentCN'] . '\';';
$errors = $conn->errorInfo(); $errors = $conn->errorInfo();
if ($errors[1] == 7 || $errors[1] ==0) if ($errors[1] == 7 || $errors[1] ==0)
echo $row['CNID'] . " linked to parent " . $row['parentCN'] . echo $row['CNID'] . " linked to parent " . $row['parentCN'] .
"<br>\n"; "<br>\n";
else print_r($errors); else print_r($errors);
} }
} }
// also need to eliminate CN 100528/100529 - check for double parent CNs with no childCN, latest sequent CN id keeps childCN = 0 // also need to eliminate CN 100528/100529 - check for double parent CNs with no childCN, latest sequent CN id keeps childCN = 0
$query = 'SELECT "parentCN", array_agg("CNID"), count(*) from contractnotice WHERE "parentCN" IN $query = 'SELECT "parentCN", array_agg("CNID"), count(*) from contractnotice WHERE "parentCN" IN
( (
SELECT "parentCN" SELECT "parentCN"
FROM contractnotice FROM contractnotice
GROUP BY "parentCN" GROUP BY "parentCN"
HAVING COUNT(*) > 1 HAVING COUNT(*) > 1
AND "parentCN" IS NOT NULL AND "parentCN" IS NOT NULL
) )
AND "childCN" IS NULL AND "childCN" IS NULL
GROUP BY "parentCN" having count(*) > 1'; GROUP BY "parentCN" having count(*) > 1';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
$cnids = explode(",",str_replace(Array("{","}"),"",$row['array_agg'])); $cnids = explode(",",str_replace(Array("{","}"),"",$row['array_agg']));
$last_cnid = array_pop($cnids); $last_cnid = array_pop($cnids);
foreach ($cnids as $cnid) { foreach ($cnids as $cnid) {
$conn->exec('UPDATE contractnotice SET "childCN" = \'' . $conn->exec('UPDATE contractnotice SET "childCN" = \'' .
$last_cnid . '\' where "CNID" = \'' . $last_cnid . '\' where "CNID" = \'' .
$cnid . '\';'); $cnid . '\';');
$errors = $conn->errorInfo(); $errors = $conn->errorInfo();
if ($errors[1] == 7 || $errors[1] ==0) if ($errors[1] == 7 || $errors[1] ==0)
echo $cnid . " linked to latest child " . $last_cnid . echo $cnid . " linked to latest child " . $last_cnid .
"<br>\n"; "<br>\n";
else print_r($errors); else print_r($errors);
} }
} }
   
?> ?>
   
<?php <?php
   
include_once("./lib/common.inc.php"); include_once("./lib/common.inc.php");
if ($_REQUEST['agency']) { if ($_REQUEST['agency']) {
   
$agency = htmlentities(strip_tags($_REQUEST['agency'])); $agency = htmlentities(strip_tags($_REQUEST['agency']));
include_header($agency); include_header($agency);
echo '<center><h1>' . $agency . '</h1></center>'; echo '<center><h1>' . $agency . '</h1></center>';
$query = 'SELECT category, min("categoryUNSPSC") AS "categoryUNSPSC", count(*) AS count, sum(value) AS value FROM contractnotice $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'; WHERE "agencyName" LIKE :agency AND ' . " " . $standardQ . ' ' . $yearQ . ' GROUP BY category ORDER BY count(*) DESC LIMIT 10';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->bindParam(":agency", $agency); $query->bindParam(":agency", $agency);
$query->execute(); $query->execute();
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
   
  $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,
  COUNT(*) AS total
  FROM contractnotice
  WHERE "supplierABN" = \'51194660183\'
  ';
  /*
  * Procurement method in text, seperate Open via SON from Open
  * Consultancies, Confidentialities percentage
  Compliance statistics: amendments, delay in reporting average and number completely late */
   
   
echo "<h3>Categories</h3><table> <thead> echo "<h3>Categories</h3><table> <thead>
<tr> <tr>
<th>Category</th> <th>Category</th>
<th>Contracts Count</th> <th>Contracts Count</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
</tr> </tr>
</thead>"; </thead>";
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);
$category = urlencode($row['category']); $category = urlencode($row['category']);
echo("<tr> echo("<tr>
<td><B><a href='displayCategory.php?category=$category'>{$row['category']}</a></b></td> <td><B><a href='displayCategory.php?category=$category'>{$row['category']}</a></b></td>
<td>{$row['count']}</td> <td>{$row['count']}</td>
<td>\$$value</td> <td>\$$value</td>
</tr>"); </tr>");
} }
echo "</table><br/>"; 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" $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 ' . " " . $standardQ . ' ' . $yearQ . 'AND contractnotice."SONID" != \'\' GROUP BY contractnotice."SONID"';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->bindParam(":agency", $agency); $query->bindParam(":agency", $agency);
$query->execute(); $query->execute();
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
$sonrows = ""; $sonrows = "";
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);
$sonrows .= "<tr> $sonrows .= "<tr>
<td><B><a href=\"displaySON.php?SONID={$row['SONID']}\">{$row['title']}</a></b></td> <td><B><a href=\"displaySON.php?SONID={$row['SONID']}\">{$row['title']}</a></b></td>
<td>{$row['count']}</td> <td>{$row['count']}</td>
<td>\$$value</td> <td>\$$value</td>
</tr>"; </tr>";
} }
if (strlen($sonrows) > 1) { if (strlen($sonrows) > 1) {
echo "<h3>Standing Offers/Panels</h3><table> <thead> 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>$sonrows</table><br/>"; </thead>$sonrows</table><br/>";
} }
   
$query = 'SELECT SUM(value) AS value, count(*), text_mode("supplierName") "supplierName", min("supplierABN") AS "supplierABN", ( $query = 'SELECT SUM(value) AS value, count(*), text_mode("supplierName") "supplierName", min("supplierABN") AS "supplierABN", (
CASE WHEN "supplierABN" != 0 THEN "supplierABN"::TEXT ELSE lower("supplierName") END) AS "supplierID" FROM contractnotice CASE WHEN "supplierABN" != 0 THEN "supplierABN"::TEXT ELSE lower("supplierName") END) AS "supplierID" FROM contractnotice
WHERE ' . $yearQ . " " . $standardQ . ' AND "agencyName" LIKE :agency WHERE ' . $yearQ . " " . $standardQ . ' AND "agencyName" LIKE :agency
GROUP BY "supplierID" ORDER BY "value" DESC'; GROUP BY "supplierID" ORDER BY "value" DESC';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->bindParam(":agency", $agency); $query->bindParam(":agency", $agency);
$query->execute(); $query->execute();
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
echo "<h3>Suppliers</h3><table> <thead> echo "<h3>Suppliers</h3><table> <thead>
<tr> <tr>
<th>Supplier</th> <th>Supplier</th>
<th>Contracts Count</th> <th>Contracts Count</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
</tr> </tr>
</thead>"; </thead>";
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);
$supplierID = $row['supplierABN'] . '-' . urlencode($row['supplierName']); $supplierID = $row['supplierABN'] . '-' . urlencode($row['supplierName']);
echo("<tr> echo("<tr>
<td><B><a href=\"displaySupplier.php?supplier=$supplierID\" >{$row['supplierName']}</a></b></td> <td><B><a href=\"displaySupplier.php?supplier=$supplierID\" >{$row['supplierName']}</a></b></td>
<td>{$row['count']}</td> <td>{$row['count']}</td>
<td>\$$value</td> <td>\$$value</td>
</tr>"); </tr>");
} }
echo "</table><br/>"; echo "</table><br/>";
/*  
* 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 "CNID", "description", "value", "agencyName", "category", $query = 'SELECT "CNID", "description", "value", "agencyName", "category",
"contractStart", "supplierName" "contractStart", "supplierName"
FROM contractnotice FROM contractnotice
WHERE ' . $yearQ . ' "agencyName" LIKE :agency AND "childCN" IS NULL WHERE ' . $yearQ . ' "agencyName" LIKE :agency AND "childCN" IS NULL
ORDER BY "value" DESC LIMIT 100'; ORDER BY "value" DESC LIMIT 100';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->bindParam(":agency", $agency); $query->bindParam(":agency", $agency);
$query->execute(); $query->execute();
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
   
echo "<h3>Contracts</h3><table> <thead> echo "<h3>Contracts</h3><table> <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>";
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 {
/* /*
split by portfolio split by portfolio
*/ */
include_header("Agencies"); include_header("Agencies");
agenciesGraph(); agenciesGraph();
$query = 'SELECT SUM("value"), "agencyName" $query = 'SELECT SUM("value"), "agencyName"
FROM contractnotice FROM contractnotice
WHERE ' . $yearQ . ' "childCN" IS NULL WHERE ' . $yearQ . ' "childCN" IS NULL
GROUP BY "agencyName" '; GROUP BY "agencyName" ';
$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>Agency</th> <th>Agency</th>
<th>Total Contracts Value</th> <th>Total Contracts Value</th>
</tr> </tr>
</thead>"; </thead>";
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[0]), 2); $value = number_format(doubleval($row[0]), 2);
$agency = stripslashes($row[1]); $agency = stripslashes($row[1]);
echo("<tr><td><b><a href=\"displayAgency.php?agency={$agency}\">{$agency}</a></b></td><td>\$$value</td></tr>\n"); echo("<tr><td><b><a href=\"displayAgency.php?agency={$agency}\">{$agency}</a></b></td><td>\$$value</td></tr>\n");
} }
echo "</table>"; echo "</table>";
} }
include_footer(); include_footer();
?> ?>
   
<?php <?php
include_once("./lib/common.inc.php"); include_once("./lib/common.inc.php");
if ($_REQUEST['SONID']) { if ($_REQUEST['SONID']) {
$query = 'SELECT title FROM standingoffers WHERE "SONID" = :SONID'; $query = 'SELECT title FROM standingoffers WHERE "SONID" = :SONID';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->bindParam(":SONID", $_REQUEST['SONID']); $query->bindParam(":SONID", $_REQUEST['SONID']);
$query->execute(); $query->execute();
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
$title = reset($query->fetchAll())['title']; $title = reset($query->fetchAll())['title'];
include_header($title); include_header($title);
echo "<center><h1>" . $_REQUEST['SONID'] . " - " . $title . "</h1></center>"; echo "<center><h1>" . $_REQUEST['SONID'] . " - " . $title . "</h1></center>";
echo '<br><a href="https://www.tenders.gov.au/?event=public.advancedsearch.CNSONRedirect&type=sonSearchEvent&SONID=' . $_REQUEST['SONID'] . '"> View original record @ tenders.gov.au</a><br>'; echo '<br><a href="https://www.tenders.gov.au/?event=public.advancedsearch.CNSONRedirect&type=sonSearchEvent&SONID=' . $_REQUEST['SONID'] . '"> View original record @ tenders.gov.au</a><br>';
/* /*
* Procurement method in text, seperate Open via SON from Open * Procurement method in text, seperate Open via SON from Open
* Consultancies, Confidentialities percentage * Consultancies, Confidentialities percentage
*/ */
$query = 'SELECT category, min("categoryUNSPSC") AS "categoryUNSPSC", count(*) AS count, sum(value) AS value $query = 'SELECT category, min("categoryUNSPSC") AS "categoryUNSPSC", count(*) AS count, sum(value) AS value
FROM contractnotice FROM contractnotice
WHERE "SONID" = :SONID WHERE "SONID" = :SONID
GROUP BY category'; GROUP BY category';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->bindParam(":SONID", $_REQUEST['SONID']); $query->bindParam(":SONID", $_REQUEST['SONID']);
$query->execute(); $query->execute();
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
echo "<h3>Categories</h3><table> <thead> echo "<h3>Categories</h3><table> <thead>
<tr> <tr>
<th>Category</th> <th>Category</th>
<th>Contracts Count</th> <th>Contracts Count</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
</tr> </tr>
</thead>"; </thead>";
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);
$category = urlencode($row['category']); $category = urlencode($row['category']);
echo("<tr> echo("<tr>
<td><B><a href='displayCategory.php?category=$category'>{$row['category']}</a></b></td> <td><B><a href='displayCategory.php?category=$category'>{$row['category']}</a></b></td>
<td>{$row['count']}</td> <td>{$row['count']}</td>
<td>\$$value</td> <td>\$$value</td>
</tr>"); </tr>");
} }
echo "</table><br/>"; echo "</table><br/>";
   
$query = 'SELECT "supplierABN", text_mode("supplierName") AS "supplierName", count(*), sum(value) AS value FROM contractnotice $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" 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 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)'; WHERE "SONID" = :SONID AND abn NOT IN (SELECT DISTINCT "supplierABN" AS abn FROM contractnotice WHERE "SONID" = :SONID)';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->bindParam(":SONID", $_REQUEST['SONID']); $query->bindParam(":SONID", $_REQUEST['SONID']);
$query->execute(); $query->execute();
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
   
echo "<h3>Suppliers</h3><table> <thead> echo "<h3>Suppliers</h3><table> <thead>
<tr> <tr>
<th>Supplier</th> <th>Supplier</th>
<th>Contracts Count</th> <th>Contracts Count</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
</tr> </tr>
</thead>"; </thead>";
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);
$supplier = stripslashes($row['supplierABN'] . '-' . $row['supplierName']); $supplier = stripslashes($row['supplierABN'] . '-' . $row['supplierName']);
echo("<tr> echo("<tr>
<td><b><a href=\"displaySupplier.php?supplier={$supplier}\">{$row['supplierName']}</a></b></td> <td><b><a href=\"displaySupplier.php?supplier={$supplier}\">{$row['supplierName']}</a></b></td>
<td>{$row['count']}</td> <td>{$row['count']}</td>
<td>\$$value</td> <td>\$$value</td>
</tr>"); </tr>");
} }
echo "</table><br/><h3>Contracts</h3><table> <thead> echo "</table><br/><h3>Contracts</h3><table> <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", title, description, value, "agencyName", contractnotice."SONID", "contractStart", "supplierName" $query = 'SELECT "CNID", title, description, value, "agencyName", contractnotice."SONID", "contractStart", "supplierName"
FROM contractnotice INNER JOIN standingoffers ON contractnotice."SONID" = standingoffers."SONID" FROM contractnotice INNER JOIN standingoffers ON contractnotice."SONID" = standingoffers."SONID"
WHERE ' . $yearQ . ' "childCN" IS NULL WHERE ' . $yearQ . ' "childCN" IS NULL
AND contractnotice."SONID" = :SONID AND contractnotice."SONID" = :SONID
ORDER BY VALUE DESC'; ORDER BY VALUE DESC';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->bindParam(":SONID", $_REQUEST['SONID']); $query->bindParam(":SONID", $_REQUEST['SONID']);
$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 {
/*  
split by main categories  
*/  
include_header("Standing Offers"); include_header("Standing Offers");
$query = 'SELECT sum(value), count(*), contractnotice."SONID", min(title) AS title, text_mode(category) as category $query = 'SELECT sum(value), count(*), contractnotice."SONID", min(title) AS title, text_mode(category) as category
FROM contractnotice INNER JOIN standingoffers ON contractnotice."SONID" = standingoffers."SONID" FROM contractnotice INNER JOIN standingoffers ON contractnotice."SONID" = standingoffers."SONID"
WHERE ' . $yearQ . ' "childCN" IS NULL AND contractnotice."SONID" != \'\' WHERE ' . $yearQ . ' "childCN" IS NULL AND contractnotice."SONID" != \'\'
GROUP BY contractnotice."SONID" ORDER BY sum(VALUE) DESC '; GROUP BY contractnotice."SONID" ORDER BY sum(VALUE) DESC ';
$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>SONID</th> <th>SONID</th>
<th>Main category</th> <th>Main category</th>
<th>Total Contracts Value</th> <th>Total Contracts Value</th>
<th>Number of Contracts</th> <th>Number of Contracts</th>
</tr> </tr>
</thead>"; </thead>";
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['sum']), 2); $value = number_format(doubleval($row['sum']), 2);
$title = $row['SONID']; $title = $row['SONID'];
if (strlen($row['title']) > 1) $title = $row['title']; if (strlen($row['title']) > 1) $title = $row['title'];
echo("<tr><td><A href=\"displaySON.php?SONID={$row['SONID']}\"><b>$title</b></a></td><td>{$row['category']}</td><td>\$$value</td><td>{$row['count']}</td></tr>"); echo("<tr><td><A href=\"displaySON.php?SONID={$row['SONID']}\"><b>$title</b></a></td><td>{$row['category']}</td><td>\$$value</td><td>{$row['count']}</td></tr>");
} }
echo "</table>"; echo "</table>";
} }
include_footer(); include_footer();
   
   
<?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>';
if ($supplierABN) { if ($supplierABN) {
$query = 'SELECT distinct on (lower("supplierName")) "supplierName" from contractnotice where "supplierABN" = :supplierABN'; $query = 'SELECT distinct on (lower("supplierName")) "supplierName" from contractnotice where "supplierABN" = :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());
echo "Also known as: ".implode(', ', $query->fetchAll(PDO::FETCH_COLUMN, 0)); echo "<b>Also known as:</b> ".implode(', ', $query->fetchAll(PDO::FETCH_COLUMN, 0));
} }
/*  
* Procurement method in text, seperate Open via SON from Open $query = '
* Consultancies, Confidentialities percentage 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,
  COUNT(*) AS total
  FROM contractnotice
  WHERE' . $supplierQ . " " . $standardQ ;
  $query = $conn->prepare($query);
  if ($supplierParts[0] > 0) {
  $query->bindParam(":supplierABN", $supplierABN);
  } else {
  $query->bindParam(":supplierName", $supplierName);
  }
  $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 $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'; WHERE ' . $supplierQ . " " . $standardQ . ' GROUP BY category ORDER BY count(*) DESC LIMIT 10';
$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());
   
   
echo "<h3>Categories</h3><table> <thead> echo "<h3>Categories</h3><table> <thead>
<tr> <tr>
<th>Category</th> <th>Category</th>
<th>Contracts Count</th> <th>Contracts Count</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
</tr> </tr>
</thead>"; </thead>";
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);
$category = urlencode($row['category']); $category = urlencode($row['category']);
echo("<tr> echo("<tr>
<td><B><a href='displayCategory.php?category=$category'>{$row['category']}</a></b></td> <td><B><a href='displayCategory.php?category=$category'>{$row['category']}</a></b></td>
<td>{$row['count']}</td> <td>{$row['count']}</td>
<td>\$$value</td> <td>\$$value</td>
</tr>"); </tr>");
} }
echo "</table><br/>"; 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" $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 WHERE ' . $yearQ . ' ' . $supplierQ . ' "childCN" IS NULL
GROUP BY abn ORDER BY SUM("value") DESC'; GROUP BY abn ORDER BY SUM("value") DESC';
$query = $conn->prepare($query); $query = $conn->prepare($query);
if (count($supplierParts) > 0) { if (count($supplierParts) > 0) {
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());
   
echo "<h3>Agencies</h3><table> <thead> echo "<h3>Agencies</h3><table> <thead>
<tr> <tr>
<th>Agency</th> <th>Agency</th>
<th>Contracts Count</th> <th>Contracts Count</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
</tr> </tr>
</thead>"; </thead>";
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);
$agency =urlencode($row['agencyname']); $agency =urlencode($row['agencyname']);
echo("<tr> echo("<tr>
<td><B><a href=\"displayAgency.php?agency=$agency\">{$row['agencyname']}</a></b></td> <td><B><a href=\"displayAgency.php?agency=$agency\">{$row['agencyname']}</a></b></td>
<td>{$row['count']}</td> <td>{$row['count']}</td>
<td>\$$value</td> <td>\$$value</td>
</tr>"); </tr>");
} }
echo "</table><br/>"; 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 . ' ' . $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 $supplierQ . ' ' . $standardQ
. ' AND contractnotice."SONID" != \'\' GROUP BY contractnotice."SONID"'; . ' AND contractnotice."SONID" != \'\' GROUP BY contractnotice."SONID"';
$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());
$sonrows = ""; $sonrows = "";
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);
$sonrows .= "<tr> $sonrows .= "<tr>
<td><B><a href=\"displaySON.php?SONID={$row['SONID']}\">{$row['title']}</a></b></td> <td><B><a href=\"displaySON.php?SONID={$row['SONID']}\">{$row['title']}</a></b></td>
<td>{$row['count']}</td> <td>{$row['count']}</td>
<td>\$$value</td> <td>\$$value</td>
</tr>"; </tr>";
} }
if (strlen($sonrows) > 1) { if (strlen($sonrows) > 1) {
echo "<h3>Standing Offers/Panels</h3><table> <thead> 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>$sonrows</table><br/>"; </thead>$sonrows</table><br/>";
} }
echo "<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();
?> ?>