Home arrow PHP arrow Invoice Management in a PHP Invoicing System

Invoice Management in a PHP Invoicing System

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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Downloadable files for this article are available here and here.

Continuing with the PHP Invoicing series, we will now concentrate on how to create, view and print an invoice. So let’s get started!

Create a new PHP document and save it as main.php. Refer to fig2 to see what the main page looks like. There are essentially three pages that deal with invoices:

  • Allinv.php – Lists all invoices in the database.
  • Unpaid.php – Lists all unpaid invoices.
  • NewInvoice.php – Enables you to generate a new invoice.

There are also related pages that handle deleting and updating invoices.

Create a new document and save it as allinvoices.php. The page consists of both PHP and HTML code. Add the following code:

Code4  Allinv.php
<?
include "config.php";
$query_invoice = "SELECT *,DATE_FORMAT(inv_date,'%D %M %Y') as
idate,DATE_ADD(inv_date,INTERVAL 30 DAY) as duedate  FROM
invoices ORDER BY invno DESC";
$result_invoice = mysql_query($query_invoice);
$num_invoice = mysql_num_rows($result_invoice);
?>

This is a standard query that retrieves all the invoices in the database. The only things worth explaining are the DATE_FORMAT() and DATE_ADD() functions. The DATE_FORMAT function does exactly what the name implies: it formats the date that is stored in the way that you want it. The DATE_ADD() function adds a specified number of days (in this case it is 30) to the date column in the database.

I wanted the date formatted as dd mm yyyy which is displayed as, for example, "18th June 2005." There are a variety of ways in which you can format a date. Check http://www.mysql.com/ for more details.  The 30 days that I’ve specified in the DATE_ADD() function will help us determine whether an invoice is overdue.

The number of rows returned by the query is stored in the "$num_invoices" variable. As you’ll see in a little while, it will be used to determine how many rows a table should have.



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

blog comments powered by Disqus
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap

Dev Shed Tutorial Topics: