PHP
  Home arrow PHP arrow Page 4 - Invoice Management in a PHP Invoicing System
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 23
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT