PHP
  Home arrow PHP arrow Page 4 - Invoice Management in a PHP Invoicing ...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Invoice Management in a PHP Invoicing System
By: Leidago
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 22
    2006-09-13

    Table of Contents:
  • Invoice Management in a PHP Invoicing System
  • Finishing the Invoice Page
  • Generating a Table
  • Code for Creating an Invoice
  • Creating Unpaid.php
  • Creating a new invoice

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Invoice Management in a PHP Invoicing System - Code for Creating an Invoice


    (Page 4 of 6 )

    Let’s take a look at the code behind creating a PDF invoice:

    <?php
    include "config.php";
    //retrieve the invoice info for the client
    $query="SELECT *,DATE_FORMAT(inv_date,'%D %M %Y') as idate FROM invoices where invno='".$_GET['cid']."'";
    $results=mysql_query($query);
    if(!$results){
    exit(mysql_error());
    }else{
    $row = mysql_fetch_array($results);
    }
    $query="SELECT name,address FROM client where id='".$_GET
    ['cid']."'";
    $result1 = mysql_query($query);
                if (!$result1) {
                   $error = mysql_error();
    }else{
    $cname = mysql_fetch_array($result1);
    }
    $pdf = pdf_new();
    //SET PDF INFO
    pdf_open_file($pdf, 'c:\\'.$cname['name'].''.$td.'.pdf');
    pdf_set_info($pdf, "Author","InvoiceGen");
    pdf_set_info($pdf, "Title","Invoice");
    pdf_set_info($pdf, "Creator", "InvoiceGen");
    pdf_set_info($pdf, "Subject", "Invoice");
    $x=595;
    $y=842;
    //start building the page
    pdf_begin_page($pdf, $x, $y);
    pdf_set_value($pdf, 'textrendering', 0); // fill
    //set the font
    $tahoma = pdf_findfont($pdf, "Tahoma", "host", 1);
    //write the word INVOICE at the top of the page
    pdf_setfont($pdf, $tahoma, 11);
    pdf_show_xy($pdf, "RE: Invoice ",250,$y-20);
    //Now add the text - your address
    pdf_setfont($pdf, $tahoma, 11);
    pdf_show_xy($pdf, 'PDF Invoice Generator plc.',400,$y-40);
    pdf_continue_text($pdf, '64 Martyn Lane');
    pdf_continue_text($pdf, 'Totley, TA4 6QQ');
    pdf_continue_text($pdf, '');
    pdf_continue_text($pdf, 'Invoice Number:'.$row['invno'].'');
    pdf_continue_text($pdf, ''.$row['idate'].'');
    //Client Address
    pdf_setfont($pdf, $tahoma, 11);
    pdf_show_xy($pdf, ''.$cname['name'].'',20,$y-100);
    pdf_continue_text($pdf, '12 Second Street');
    pdf_continue_text($pdf, 'Yoeville, Y19 3AS');
    pdf_setfont($pdf, $tahoma, 11);
    pdf_show_xy($pdf, "RE: Invoice ",250,$y-20);
    //Draw the lines
    $offset = 184; $i=0;
    pdf_moveto($pdf, 20,$y-160);
    pdf_lineto($pdf, $x-20,$y-160);
    pdf_stroke($pdf);
    pdf_moveto($pdf, $x-140,$y-160);
    pdf_lineto($pdf, $x-140,80);
    pdf_stroke($pdf);
    //Add product description and cost on top of the line
    pdf_setfont($pdf, $tahoma, 11);
    pdf_show_xy($pdf, "Product Description",30,$y-150);
    pdf_show_xy($pdf, "Total(incl. VAT)",$x-100,$y-150);
    //write the items for which the invoice was issued
    pdf_setfont($pdf, $tahoma, 10);
    pdf_show_xy($pdf, "".$row['descr']."",20,$y-200);
    pdf_show_xy($pdf, "".$row['totwvat']." ",$x -100,$y-200);
    pdf_setfont($pdf, $tahoma, 8);
    pdf_continue_text($pdf, '');
    pdf_continue_text($pdf, '');
    pdf_continue_text($pdf, 'VAT charged @ 17.5');
    pdf_end_page($pdf);
    pdf_close($pdf);
    ?>

    I will not explain everything about creating a PDF document because it is an entire subject in its own right. I’ve put some comments in the code to give you a general idea of what is going on. Also, it might be useful if you can read the excellent article on the Dev Articles site that demonstrates how to create a PDF document with PHP. It is very basic but it will give you a very good start in exploring the various functions available. And believe me, there are a lot of PDF functions. The important ones that you need to know are:

    pdf_open_file() – Creates a blank pdf file.

    pdf_set_info()   - Assigns properties to a pdf file, such as the name of the author, title and subject of the file.

    pdf_begin_page() – This function allows you to set the width and height of the page. Currently there are three defined measures, each defining a particular type of  page:

    • A4 = 595 x 842
    • Letter = 612 x 792
    • Legal = 612 x 1008

    pdf_findfont() – Searches for a font type in the location that you specify.

    pdf_setfont() – Sets the font type  that you specified above.

    pdf_show_xy() – Writes text to a specified location on a page. X defines the horizontal location and Y defines the vertical location.

    pdf_continue_text() – Writes the text on the next line; basically inserts a line break.

    pdf_end_page() – Shows the end of the page.

    pdf_close() – Frees the pdf object.

    The above functions are enough to create a simple PDF document.  For more information on how to use PDF functions in PHP, visit http://www.php.net/.

    That’s all there is to showing a list of invoices in the database.

    More PHP Articles
    More By Leidago


       · As one can read in the comments on the first of this series, there is no data...
       · Minor Snark - 17.5% does equal x times 17.5 divided by 100, but it would be better...
       · Thanks for the observation. Will keep it in mind next time around!
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT