-
Notifications
You must be signed in to change notification settings - Fork 2
/
bill.php
103 lines (84 loc) · 2.7 KB
/
bill.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<html>
<head>
<title>BILL</title>
</head>
<body>
<?php
$customer_phone = $_POST['customer_phone'];
$con = mysql_connect('localhost', 'root', 'ashg123');
mysql_select_db('db_project', $con);
$customer_phone = mysql_real_escape_string($customer_phone);
$query = "SELECT balance FROM customer WHERE Phone = '$customer_phone';";
$result = mysql_query($query);
if(mysql_num_rows($result) == 0)
{
echo 'Customer Not Registered!';
}
else
{
$total = 0;
$customerData = mysql_fetch_array($result, MYSQL_ASSOC);
$balance = $customerData['balance'];
$query = "SELECT bill_no FROM billing_details ORDER BY bill_no DESC LIMIT 1;";
$result = mysql_query($query);
if(mysql_num_rows($result) == 0)
{
$bill_number = 1;
}
else
{
$billData = mysql_fetch_array($result, MYSQL_ASSOC);
$bill_number = $billData['bill_no'] + 1;
}
$query = "SELECT * FROM bill_produce;";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$price_discount = $row['price_discount'];
$item_code = $row['item_code'];
$price = $row['price'];
$discount = $row['discount'];
$total = $total + $price_discount;
$query = "SELECT Quantity FROM item_details;";
$result = mysql_query($query);
$itemData = mysql_fetch_array($result, MYSQL_ASSOC);
$quantity = $itemData['Quantity'] - 1;
$query = "UPDATE item_details SET Quantity = $quantity;";
$result = mysql_query($query);
$query = "INSERT INTO sales_details (Item_id,Price,Discount,bill_number) VALUES('$item_code','$price','$discount','$bill_number');";
$result = mysql_query($query);
$query = "DELETE FROM bill_produce WHERE item_code = '$item_code'; ";
$result = mysql_query($query);
$query = "SELECT * FROM bill_produce;";
$result = mysql_query($query);
}
if($total > $balance)
{
$total = $total - $balance;
$balance = 0;
}
else
{
$balance = $balance - $total;
$total = 0;
}
$today = getdate();
$day = $today['mday'];
$month = $today['mon'];
$year = $today['year'];
$query = "INSERT INTO billing_details (day,month,year,amount,customer_id) VALUES ('$day','$month','$year','$total','$customer_phone');";
$result = mysql_query($query);
$query = "UPDATE customer SET balance='$balance',day='$day',month='$month',year='$year' WHERE Phone='$customer_phone';";
$result = mysql_query($query);
echo "<br>BILL NUMBER: " . $bill_number . "</br>";
echo "<br>DATE: " . $day ."/". $month ."/". $year ."</br>";
echo "<br>AMOUNT: " . $total . "</br>";
echo "<br>BALANCE: " . $balance . "</br>";
}
?>
<br></br>
<a href="./purchase_item.php">Make Another Purchase</a>
<br></br>
<a href="./cashier.php">Back to home</a>
</body>
</html>