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
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- 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: