To create a invoice is relatively simple. All we need to do is find out how much your invoice is, who you are invoicing and what the invoice is for. In terms of coding we will of course need a lot more information, such as who is making the invoice, and we also have to work out the total amount with and without the VAT. Before we go further, take a look at what the "newinvoice.php" page looks like:
So, create a new document and save it as newinvoice.php. As always, go right to the top of the page and add the following code: Code6 newinvoice.php If you look at the second line of the code, you should see the following: include "FCKeditor/fckeditor.php"; http://images.devshed.com/ds/stories/PHP_Invoice/FCKeditor.zip The FCKEditor is, as the name implies, a text editor for web applications. It basically provides HTML text formatting and many other features such as smilies, image management, and so on. It is freely available online; just google for it and you should get a lot of links to it. Now I’ve marked sections of the code with the letters A and B; this is so that you know what section I’m talking about when I explain the code. It goes without saying that you should remove them when testing the code. Section A deals with calculating the total amount with VAT included. Currently in the UK, the VAT is at 17.5; it may be different where you live. So, to find out what 17.5 of the total is, we multiply the total by 17.5 and then divide the result by 100; that should give us the answer we need. Then we simply add the answer to the total entered in the form: $tot = $_POST['totxvat'] * 17.5; On the form is a dropdown box that contains all the names in the clients table. The dropdown box is dynamically filled with the names, like so: <select name="cname" id="cname"> When the form is submitted, the id of the selected client is sent to the script at the top of the page. So, after calculating the VAT, a query is executed to find the name of the client matching the submitted id, and the name of that client is stored in the "$thename" variable : $queryname="SELECT name FROM client WHERE id = '".$_POST Section B primarily inserts the newly created invoice into the appropriate database tables: $query_ins = "INSERT INTO invoices SET status='Unpaid',"; I think for the most part the fields used here are self explanatory, except maybe for the cid and uID fields. The cid field identifies the client and the uID field identifies the user who issued the invoice. The reason I use numbers instead of the actual names of the client and user is because it is generally faster to work with numbers than text when using databases. The form that takes input from the user looks like this: <form action="NewInvoice.php" method="post" name="newinv"> Here we take the description of the invoice using the FCKeditor: <tr> You do not have to use the fckeditor. You can simply use a normal HTML text box, if you like. That’s basically it for creating a new invoice. In the next article, we will be looking at client management.
blog comments powered by Disqus |
|
|
|
|
|
|
|