Ex No: 2 |
Write a program to Perform EB Bill Calculation |
Aim: |
To perform EB Bill calculation using php |
Algorithm |
|
|
Step1: Design a webpage to get EB Service Number, Customer Name and Units consumed |
|
Step2: On form submit check if units consumed is set and not empty |
|
A) Get values of Service Number, Customer Name and Units Consumed from POST method |
|
B) If Units consumed is less than 100 then display total charge as zero |
|
C) Else if Units consumed is greater than 100 and less than 200 then |
|
i) Calculate rate as 1.5 * (units - 100) |
|
ii) Service charge as 20 |
|
iii) Calculate total charge as rate + service charge |
|
D) Else if Units consumed is greater than 200 and less than 500 then |
|
i) Calculate rate as 2 * (units - 100) |
|
ii) Service charge as 30 |
|
iii) Calculate total charge as rate + service charge |
|
E) Else |
|
i) Calculate rate as 4 * (units - 100) |
|
ii) Service charge as 50 |
|
iii) Calculate total charge as rate + service charge |
|
F) Display the Generated Bill |
Source Code |
|
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>EB Bill Calculation</title>
</head>
<body>
<h3>EB Bill Calculation</h3>
<div style="float: left; width: 500px;">
<form id="ebbillform" name="ebbillform" method="POST" action="ex2.php">
<table>
<tr>
<td>Service Number:</td>
<td><input type="text" id="serno" name="serno"/></td>
</tr>
<tr>
<td>Name:</td>
<td><input type="text" id="name" name="name"/></td>
</tr>
<tr>
<td>Units Consumed:</td>
<td><input type="text" id="unit" name="unit"/></td>
</tr>
<tr>
<td><input type="submit" value="Calculate"/></td>
<td><input type="reset"/></td>
</tr>
</table>
</form>
</div>
<div style="float: left;">
Tarrif Chart
<table border="1" style="text-align: center;">
<tr> <th>Units</th><th>Rate in<br> Rupees</th> </tr>
<tr> <td>0-100</td><td>0</td> </tr>
<tr> <td>101-200</td><td>1.50 + 20</td> </tr>
<tr> <td>201-500</td><td>2.00 + 30</td> </tr>
<tr> <td>above 500</td><td>6.00 + 50</td> </tr>
</table>
</div>
</body>
</html>
ex2.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>EB Bill Calculation</title>
</head>
<body>
<?php
if(isset($_POST["unit"]) && $_POST["unit"]!="")
{
$serviceno = $_POST["serno"];
$name = $_POST["name"];
$unit = $_POST["unit"];
$serv=0;
$total=0;
$rate=0;
$opt = $unit/100;
if($unit>0 && $unit<=100)
{
$rate = 0;
$serv = 0;
$total = 0;
}
else if($unit>100 && $unit<=200)
{
$rate = 1.5 * ($unit-100);
$serv = 20;
$total = $rate + $serv;
}
else if($unit>200 && $unit<=500)
{
$rate = 2 * ($unit-100);
$serv = 30;
$total = $rate + $serv;
}
else
{
$rate = 4 * ($unit-100);
$serv = 50;
$total = $rate + $serv;
}
?>
<h4>EB Bill Generated for Service No. <?php echo $serviceno; ?></h4>
<table>
<tr>
<td>Name: </td> <td><?php echo $name; ?></td>
</tr>
<tr>
<td>Units: </td> <td><?php echo $unit; ?></td>
</tr>
<tr>
<td>Rate: </td> <td>Rs. <?php echo $rate ?></td>
</tr>
<tr>
<td>Service: </td> <td>Rs. <?php echo $serv ?></td>
</tr>
<tr>
<td>Total: </td> <td>Rs. <?php echo $total ?></td>
</tr>
</table>
<?php
}
?>
|
Result: |
Thus a webpage is designed using php to perform EB Bill Calcualtion.. |