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

# Our boilerplate include file
include ('standardinclude.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("$settingspath/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 cellpadding=2>\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";
  # convert transaction type to English
  $type_name       = fetch_name($row[type_id], $type_name, 'type', $link);
  echo "<td>$type_name</td>\n";
  echo "<td>$row[problem]</td>\n";
  # convert technician ID to English
  $technician_name       = fetch_name($row[technician_id], $technician_name, 'technician', $link);
  echo "<td>$technician_name</td>\n";
  echo "<td>$row[purchase_order]&nbsp;</td>\n";
  echo "<td>$row[project_reference]&nbsp;</td>\n";
  if ($row[paid] == 1) {
    echo "<td>Yes</td>\n";
  } else {
    echo "<td>No</td>\n";
  }
  echo "<td>\n";
  echo "<form action=\"printinvoice.php\" method=\"POST\" enctype=\"text\" target=\"_new\">\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 "</form>\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);


###############################################################################################
#                                      print footer                                           #
###############################################################################################

include("$settingspath/plainfooter.inc");

?>
