<?php
# Here we are trying to list all of the invoices sent to a particular company

#
# this defines getpostvars()
include('getpostvars.inc');

# let's set up our database connection
include ('database.inc');

# the wrapper I wrote to help with database calls
include ('keyvalue.inc');

# here we send our POST variables off to be processed
$company_id			= getpostvars('company_id', 11);

###############################################################################################
#                                       print header                                          #
###############################################################################################

$title	= 'List Invoices By Company';
include('header.inc');

###############################################################################################
#                          retrieve company info from database                                #
###############################################################################################

echo "<big><b>Company Information</b></big><br>";
include('showcompany.inc');
echo "<p>&nbsp;</p>\n";

###############################################################################################
#                          pull rows from transaction database                                #
###############################################################################################

echo "<table border=1>\n<tr>\n";
echo "<th>Date</th>\n";
echo "<th>Transaction</th>\n";
echo "<th>Type</th>\n";
echo "<th>Problem</th>\n";
echo "<th>Technician</th>\n";
echo "<th>Purchase Order</th>\n";
echo "<th>Project</td>\n";
echo "<th>Paid?</th>\n";
echo "<th colspan=2>Actions</th>\n";
echo "</tr>\n";


# here we set up the fields we want to grab
$fields		= 'transaction_id, transaction_date, type_id, problem, technician_id, ';
$fields		.= 'purchase_order, project_reference, company_id, paid';

$query	= "SELECT $fields FROM transaction WHERE company_id = $company_id";
$result = mysql_query($query, $link);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  echo "<tr>\n";
  echo "<td>$row[transaction_date]</td>\n";
  echo "<td>$row[transaction_id]</td>\n";
  echo "<td>$row[type_id]</td>\n";
  echo "<td>$row[problem]</td>\n";
  echo "<td>$row[technician_id]</td>\n";
  echo "<td>$row[purchase_order]</td>\n";
  echo "<td>$row[project_reference]</td>\n";
  echo "<td>$row[paid]</td>\n";
  echo "<td>\n";
  echo "<form action=\"printinvoice.php\" method=\"POST\" enctype=\"text\">\n";
  echo "<input type=hidden name=\"transaction_id\" value=\"$row[transaction_id]\">\n";
  echo "<input type=submit value=\"Print\">\n";
  echo "</form>\n</td>\n";
  echo "<td>\n";
  echo "<form action=\"updateinvoice.php\" method=\"POST\" enctype=\"text\">\n";
  echo "<input type=hidden name=\"transaction_id\" value=\"$row[transaction_id]\">\n";
  echo "<input type=submit value=\"Edit\">\n";
  echo "</form> </td></tr>\n";
  echo "</tr>\n";
}

echo "</table>\n";

#echo "<P>";
#print_r($_POST);
?>
