<?php
# We're including this code in creatinvoice.php if $verified is not set to 'true'



###############################################################################################
#                           date and transaction type table                                   #
###############################################################################################

?>

<form action="<?= $PHP_SELF ?>" method="POST" enctype="text">
<?php
# grab today's date if requested
if ($today == "true") {
    # need to end up on YYYY-MM-DD format
    # calculate $transaction_date later
    $month	= date("m");
    $day	= date("j");
    $year	= date("Y");
};
?>

<big><b>Date and Invoice Information</b></big><br>
<table cols=2>
  <tr>
    <td><b>Date:</b>&nbsp;
      <input type="text" name="month" value="<?= $month ?>" size=2> /
      <input type="text" name="day" value="<?= $day ?>" size=2> /
      <input type="text" name="year" value="<?= $year ?>" size=4>
    </td>
    <td><b>Transaction type:</b>

      <?php
      # radio selection carried over from previous screen
      switch($type_name)
      {
        case 'Invoice':
          $invoicechecked = 'checked';
          break;
        case 'Estimate':
          $estimatechecked = 'checked';
          break;
        case 'Proposal':
          $proposalchecked = 'checked';
          break;
      };
      ?>

      &nbsp;<input type=radio name="type_name" <?= $invoicechecked ?> value="Invoice"> Invoice
      &nbsp;<input type=radio name="type_name" <?= $estimatechecked ?> value="Estimate"> Estimate
      &nbsp;<input type=radio name="type_name" <?= $proposalchecked ?> value="Proposal"> Proposal
    </td>
  </tr>
  <tr>
    <td><input type=checkbox name="today" value="true"> The work is being completed today. </td>
    <td> </td>
  <tr>
    <td><b>Invoice Number:</b>
     <?php print $transaction_id;
      # I took out the form field here... when i write an update screen,
      # I'll have to carry $transaction_id again
      ?>  </td>
    <td>  </td>
</table>


<?php
###############################################################################################
#                          retrieve company info from database                                #
###############################################################################################

print "<big><b>Company Information</b></big><br>";

# next we grab the data for the company from the database
include ('showcompany.inc');

# here we embed $company_id into the form
print "<input type=hidden name=\"company_id\" value=\"$company_id\">\n";

###############################################################################################
#                              description of work performed                                  #
###############################################################################################
?>

<p><big><b>Problem Reported</big></b>
<br><textarea name="problem" value="<?= $problem; ?>" cols="80" rows="5"><?= $problem; ?></textarea>

<p><big><b>Description of work performed</big></b>
<br><textarea name="solution" value="<?= $solution; ?>" cols="80" rows="5"><?= $solution; ?></textarea>

<?php
#<p><b>Technician's username:</b> <input type="text" name="technician_id" value="<?= $technician_id; ? >" size=12>

print "<p><b>Technician's username:</b>\n";
dropdown_select_id ($technician_id, 'technician', $link);
?>



<?php
###############################################################################################
#                                      materials used                                         #
###############################################################################################
#
# here we twiddle the number of lines showing in the materials form
# we need to start out with at least 5 lines in the form
if ($material_lines == '') {
  $material_lines	= 5;
}
#
# we check to see if more lines of material are needed, and increment if necessary
if ($more_material == 'true') {
  $material_lines	= $material_lines + 5;
}

print "<input type=hidden name=\"material_lines\" value=\"$material_lines\">\n";

?>

<p><big><b>Materials Used</big></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Need to add more lines of material? <input type=checkbox name="more_material" value="true">
<table border=1 width="100%">
  <tr>
    <th>
      Quantity
    </td>
    <th>
      Description
    </td>
    <th>
      Unit Price
    </td>
    <th>
      Extended
    </td>
  </tr>

  <?php

  # loop places materials into an array
  for ($line=1; $line <= $material_lines; $line++) {

    # here we $_POST the materials variables
    $materials[$line]["quantity"] = $_POST["materials"][$line]["quantity"];
    $materials[$line]["item_description"] = $_POST["materials"][$line]["item_description"];
    $materials[$line]["unitprice"] = $_POST["materials"][$line]["unitprice"];

    print "<tr>\n";
    print "<td align=\"center\"><input type=\"text\" name=\"materials[$line][quantity]\"
      size=4 value=\"" . $materials[$line]["quantity"] . "\">  </td>\n";
    print "<td align=\"left\"><input type=\"text\" name=\"materials[$line][item_description]\"
      size=60 value=\"" . $materials[$line]["item_description"] . "\">  </td>\n";
    print "<td align=\"right\"><input type=\"text\" name=\"materials[$line][unitprice]\"
      size=9 value=\"" . $materials[$line]["unitprice"] . "\">  </td>\n";
    $extended	= $materials[$line]["quantity"] * $materials[$line]["unitprice"];
    $materialtotal	= $materialtotal + $extended;
    print "<td align=\"right\">\$" . number_format($extended,2) . "  </td>\n";
    print "</tr>\n";
  }

  # labor rate
  $labortotal	= $labor_hours * $labor_rate;

  print "<tr>\n";
  print "<td align=\"center\"><input type=\"text\" name=\"labor_hours\"
    size=4 value=\"" . $labor_hours . "\"></td>";
  print "<td align=\"left\">hours labor</td>";
  print "<td align=\"right\"><input type=\"text\" name=\"labor_rate\"
    size=9 value=\"" . $labor_rate . "\"></td>";
  print "<td align=\"right\">$" . $labortotal . "</td>";
  print "</tr>\n";

  # here we have to add up all the numbers and print out our totals
  include ('totalstable.inc');
  ?>

</table>

<?php
###############################################################################################
#                                      form submittal                                         #
###############################################################################################
?>

<p><input type=checkbox name="verified" value="true"> All data has been verified.
<p><input type=submit value="Submit"></p>
</form>

