Home arrow PHP arrow Page 3 - Invoice Management in a PHP Invoicing System

Generating a Table - PHP

If you're running a business in which you're invoicing clients, you need some way to keep track of which invoices have gone out and which clients have paid. In this second article of a four-part series that covers the creation of a PHP invoicing system, we create the parts that deal with this kind of invoice management.

  1. Invoice Management in a PHP Invoicing System
  2. Finishing the Invoice Page
  3. Generating a Table
  4. Code for Creating an Invoice
  5. Creating Unpaid.php
  6. Creating a new invoice
By: Leidago
Rating: starstarstarstarstar / 31
September 13, 2006

print this article



The next part of the table is dynamically generated based on the retrieved data. First, PHP checks to see if the returned results are greater than zero. If they are, it then matches and lists the data from the database to the table headings:

                        if($num_invoice > 0){
                        while($invoice = mysql_fetch_assoc($result_invoice)){
        <tr valign="top" class="tblinfo">
          <td><? if($td > $invoice['duedate']){
                          echo "<font color=\"#FF0000\">Overdue</font>";
                          echo $invoice['status'];}
                          <? $query_invdetails = "SELECT * FROM clientinv WHERE
if(!$result_invdetails= mysql_query($query_invdetails)){
echo mysql_error();
$num_invdetails = mysql_num_rows($result_invdetails);
          <td><a href="invView.php?iid=<?=$invoice['invno']?>">View </a> |<a
href="delinvoice.php?iid=<?=$invoice['invno']?>">Delete</a> <a href="edInv.php?
iid=<?=$invoice['invno']?>">Update</a> <? if($td > $invoice['duedate']){
                          echo "<img src=\"images/RedFlag.gif\" height = \"10\"/>"; 
                          <? if(isset($email)){?>
                          <a href="emailInv.php?iid=<?=$invoice['invno']?>">Email
                          <? }?>
                           <a href="pdf.php?cid=<?=$invoice['cid']?>"><img
src="images/pdf.gif" width="18" height="18" border="0"/></a></td>
                        <? }

The action column is in itself very dynamic, in that it compares the invoice due date with todayís date and based on the result, shows an email reminder link. An invoice becomes overdue if it is 30 days late, in which case a red flag is displayed alongside the reminder link.

You will also notice another query. This query interrogates the clientinvoice table to get the invoice description and totals. This query is located where it is because it needs the invoice ID of the current invoice in the "while loop." Finally, if the value in the $num_invoices() is less than one, then no rows have been returned by the query, so an appropriate message is shown:

<? }
                        }else{ ?>
                        <td colspan="7"><p>No invoices available at present.</p></td>
                        <? }?>

Another feature of the "actioní"column is that it displays a PDF logo. When you click on it, you automatically create a pdf invoice, that will have the name of the client and current date as its name, which you can then use to email to the client. Iíve not automated the process of emailing the PDF, as Iíve already dealt with emailing clients when an invoice is "unpaid" or overdue. Below is a screenshot of what our invoice is going to look like:

>>> More PHP Articles          >>> More By Leidago

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: