<?php
# Here we are trying to list monthly and yearly activity

# Our boilerplate include file
include ('standardinclude.inc');

# here we send our POST variables off to be processed
$year         = getgetvars('year', 4);
$month        = getgetvars('month', 2);

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

$title        = 'Report By Month';
include("$settingspath/header.inc");

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

$monthnames      = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
print "<big><b>Report for $monthnames[$month], $year</b></big><br>";

print "<table border=1 cellpadding=0>\n<tr>\n";
print "<th>Date</th>\n";
print "<th>Transaction</th>\n";
print "<th>Company</th>\n";
print "<th>Total</th>\n";
print "<th>Action</th>\n";
print "</tr>\n";

# we want to print the total due for each invoice
include('gettotal.inc');

# And also keep a running total of all balances
$runningtotal = 0;

# here we set up the fields we want to grab

$month = $month + 100;
$date = $year . '-' . substr($month, -2) . '%';

$query        = "SELECT transaction.transaction_id, transaction.transaction_date, transaction.labor_hours,";
$query        .= " transaction.labor_rate, transaction.tax_rate, transaction.company_id, company.company_name";
$query        .= "  FROM transaction, company WHERE transaction.company_id = company.company_id";
$query        .= "  and transaction.transaction_date like '$date' and transaction.type_id = 'IN'";
#print "<b>QUERY:</b> $query<br><br>\n";

$transactions = mysql_query($query, $link);

while ($row = mysql_fetch_array($transactions, MYSQL_ASSOC)) {
  print "<tr>\n";
  print "<td>$row[transaction_date]</td>\n";
  $transaction_id   = $row[transaction_id];       # I hate doing stuff more than once
  print "<td>$transaction_id</td>\n";
  print "<td><a href=\"listbycompany.php?company_id=$row[company_id]&by_get=1\">$row[company_name]</a></td>\n";
  $grandtotal       = get_total($transaction_id, $grandtotal, $link);
  print "<td>\$" . number_format($grandtotal,2) . "</td>\n";
  print "<td>\n";
  print "<form action=\"printinvoice.php\" method=\"POST\" enctype=\"text\">\n";
  print "<input type=hidden name=\"transaction_id\" value=\"$row[transaction_id]\">\n";
  print "<input type=submit value=\"Print\">\n";
  print "</form> </td></tr>\n";

  # Tally the balance.
  $runningtotal     = $runningtotal + $grandtotal;
}

print "</table>\n";

print "<p>&nbsp;</p>";
print "<big><b>Running balance: $" . number_format($runningtotal,2) . "</b></big><br>\n";

#print "<P>";
#print_r($_POST);


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

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

?>
