Invoice Management System in PHP with Source Code

Here, we will create a simple form to allow a user to choose a product and enter the quantity he/she wants to purchase and will generate an Invoice. By Jyoti Singh Last updated : December 20, 2023

Invoice Management System in PHP

In this problem you have to make a form in html with the following fields:

  1. Product (use select tag to make a drop down)
  2. Quantity of product

Invoice should contain following:

  1. Serial number
  2. Product name
  3. Product Picture
  4. Product Rate
  5. Product Quantity
  6. Discount
  7. Amount
  8. Net Amount (Amount - Discount)

Prerequisites

To understand this example, you should have the basic knowledge of the following PHP topics:

Let's start to solve this problem:

To make your form make a file named "product.php" and write below code:

HTML Code

<html>
  <form action="bill.php">
    <center>
    <table>
      <caption>
        <font color='blue' size='6'>Select Your Product</font>
      </caption>
      <br><br>
      <tr>
        <td>Choose Product:</td>
        <td>
          <select name=prd>
            <option>Product 1</option>
            <option>Product 2</option>
            <option>Product 3</option>
            <option>Product 4</option>
          </select>
        </td>
      <tr>
        <td>Quantity:</td>
        <td><input type=text name=qty></td>
      </tr>
      <tr>
        <td><input type=submit></td>
        <td><input type=reset></td>
      </tr>
    </table>
    <center>
  </form>
</html>

Now run your php file by using url → 'localhost/foldername/product.php'

You would see your result like this:

Invoice example in PHP - HTML form

It's time to make the invoice. Make a file named "bill.php" and add following code in it:

PHP Code with HTML

<html>
  <?php
    $prd=$_GET['prd'];
    $qty=$_GET['qty'];
    $rate=0;
    $img="";
    
    if($prd=="Product 1")
    {
    	$rate=400;
    	$img='p1.png';
    }
    else if($prd=="Product 2")
    {
    	$rate=150;
    	$img='p2.jpg';
    }
    else if($prd=="Product 3")
    {
    	$rate=50;
    	$img='p3.jpg';
    }
    else if($prd=="Product 4")
    {
    	$rate=30;
    	$img='p4.png';
    }
    $amt=$rate*$qty;
    $dis=$amt*5/100;
    $na=$amt-$dis;
    
    ?>
  <center>
    <table border=1 width=70%>
      <caption>
        <font color='blue' size='8'> Invoice</font>
      </caption>
      <br><br>
      <tr>
        <th>S.No</th>
        <th>Description</th>
        <th>Rate</th>
        <th>Qty</th>
        <th>Amount</th>
        <th>Discount</th>
        <th>Net Amount</th>
      </tr>
      <tr>
        <td>1</td>
        <td>
          <?php echo "$prd<br><img src=$img width=60 height=60>";?>
        </td>
        <td>
          <?php echo "$rate";?>
        </td>
        <td>
          <?php echo "$qty";?>
        </td>
        <td>
          <?php echo "$amt";?>
        </td>
        <td>
          <?php echo "$dis";?>
        </td>
        <td>
          <?php echo "$na";?>
        </td>
      </tr>
    </table>
  </center>
</html>

Code Explanation

This code fetches the value of quantity and product (chosen by user), sets a rate and discount according to the product choose by user and calculates the total amount and net amount. You can replace the product 1, product 2 ... product 4 values in html form select tag.

As the user hits the submit button after choosing the product and entering the quantity. It will land on Invoice page and you would see like this:

Invoice example in PHP - Output

PHP Database Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.