HomePHP 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.
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:
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{ ?> <tr> <td colspan="7"><p>No invoices available at present.</p></td> </tr> <? }?>
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: