-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboxbalance_added.php
More file actions
100 lines (65 loc) · 2.77 KB
/
boxbalance_added.php
File metadata and controls
100 lines (65 loc) · 2.77 KB
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
<?php
session_start();
date_default_timezone_set('Asia/Kolkata');
$today=date('d-M-y');
$updated_time= date('d-M-y h:i a', time());
$month=date('M');
$year=date('Y');
$name=$_SESSION['name'];
$user=implode($name);
$entered_amount = $_SESSION['boxamount'];
include("./database/db_connection.php");
if(!empty($_POST))
{
if(isset($_POST['correct']))
{
//$sql="INSERT INTO `room_amount_to_box` (`Date`, `Month`, `Year`, `Amount`, `Added By`) VALUES ('$today', '$month', '$year', '$entered_amount', '$user')";
$check=mysqli_query($con, "SELECT `id`, `Amount`, `last_updated` FROM `current_boxbalance`");
$row=mysqli_fetch_assoc($check);
$available_box_amount=$row['Amount'];
$check2=mysqli_query($con, "SELECT SUM(Amount) AS `amount_spent` FROM `room_amount_to_box` WHERE `Year`=$year AND `Month`='$month'");
$row2=mysqli_fetch_assoc($check2);
$total_room_amount_spent=$row2['amount_spent'];
//$total_amount=$available_box_amount+$entered_amount;
$total_amount=$total_room_amount_spent+$entered_amount;
/*echo "total_room_amount_spent=$total_room_amount_spent <br>";
echo "total_amount=$total_amount <br>";
echo "entered_amount=$entered_amount <br>";*/
if(mysqli_num_rows($check)>=1)
{
#total available balance in room
$retrive=mysqli_query($con, "SELECT SUM(t.Amount) AS total_available_balance FROM (SELECT Amount FROM `roomrent` WHERE Month='$month' AND Year=$year UNION ALL SELECT Balance FROM lastmonth_balance WHERE Month='$month' AND Year=$year) t ");
$row3=mysqli_fetch_assoc($retrive);
$roomrent_amount=$row3['total_available_balance'];//this amount always constant
//echo "roomrent_amount=$roomrent_amount";
if($total_amount>$roomrent_amount)
{
header("location:noamount.php");
//echo "check";
}
else
{
$sql="INSERT INTO `room_amount_to_box` (`Date`, `Month`, `Year`, `Amount`, `Added By`) VALUES ('$today', '$month', '$year', '$entered_amount', '$user')";
if ($con->query($sql)===TRUE) {
# code...
$query1="UPDATE `current_boxbalance` SET `Amount`=Amount+$entered_amount, `last_updated`='$updated_time', `Addedby`='$user'";
if($con->query($query1)===TRUE)
{
header("location:boxbalance_success.php");
}
}
}}
else
{
$sql="INSERT INTO `room_amount_to_box` (`Date`, `Month`, `Year`, `Amount`, `Added By`) VALUES ('$today', '$month', '$year', '$entered_amount', '$user')";
if ($con->query($sql)===TRUE) {
# code...
$insert="INSERT INTO `current_boxbalance` (`Amount`, `last_updated`, `Addedby`) VALUES ('$entered_amount', '$updated_time', '$user')";
if($con->query($insert)===TRUE)
{
header("location:boxbalance_success.php");
}
}}
}
}
?>