<?php
# This block of code takes the numbers from the materials and labor table fragment
# and crunches them, giving a human-readable printout. Since we don't store the subtotals
# and grandtotal in the database, we have to calculate these numbers.
#
# The point here is to not have to type or paste this into more than one file, hence an include.

$subtotal		= $materialtotal + $labortotal;

# ok, let's try and fix this...
$whatistaxed	= 'on materials';
$taxonmaterial	= ($materialtotal * $tax_rate) / 100;
if ($is_labor_taxed == 1) {
  $taxonlabor	= ($labortotal * $tax_rate) / 100;
  $whatistaxed	.= ' and labor';
} else {
  $taxonlabor	= 0;
}
$salestax		= $taxonmaterial + $taxonlabor;

$grandtotal		= $subtotal + $salestax;


?>

<tr>
  <td> </td>
  <td> </td>
  <td> </td>
  <td> </td>
<tr>
<tr>
  <td></td>
  <td></td>
  <td align="right"><b>Subtotal:</b></td>
  <td align="right"><b>$<?= number_format($subtotal,2) ?></b></td>
</tr>
  <tr>
  <td></td>
  <td></td>
  <td align="right"><b><?= $tax_rate ?>% Sales Tax <?= $whatistaxed; ?>:</b></td>
  <td align="right"><b>$<?= number_format($salestax,2) ?></b></td>
</tr>
<tr>
  <td></td>
  <td></td>
  <td align="right"><big><b>TOTAL:</b></big></td>
  <td align="right"><big><b>$<?= number_format($grandtotal,2) ?></b></big></td>
</tr>
