-
Notifications
You must be signed in to change notification settings - Fork 0
/
editTransaction.php
120 lines (109 loc) · 5.75 KB
/
editTransaction.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
include 'connection.php';
session_start();
if (!isset($_SESSION['id']) || !isset($_SESSION['role'])) {
header('Location: login.php');
exit;
}
include_once('includes/header.php');
$id = $_REQUEST['id'];
$str = "SELECT transaction.*, customers.name as user_name, customers.phone as phone FROM transaction LEFT JOIN customers ON transaction.user_id = customers.id WHERE transaction.id = $id";
$result = mysqli_query($conn, $str);
$transaction = mysqli_fetch_assoc($result);
if (isset($_POST['submit'])) {
$advance = $_POST['advance'];
$total = $_POST['total'];
$cash = $_POST['cash'];
$method = $_POST['method'];
// Calculate due based on the formula due = total - advance
$due = $total - $advance;
// Update the database with the new values
// Update the database with the new values
$str = "UPDATE transaction SET advance='" . $advance . "', total='" . $total . "', due='" . $due . "', cash='" . 0 . "', method='" . $method . "' WHERE id= $id";
if (mysqli_query($conn, $str)) {
echo "<script> window.location.replace('transaction.php'); </script>";
}
}
?>
<style>
.container-center {
display: flex;
justify-content: center;
align-items: center;
}
</style>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header text-center">Update Transaction</h1>
</div>
</div>
<div class="row">
<div class="container-center">
<div class="col-md-8">
<form method="post" action="">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title text-center " style="font-weight: bold;">Transaction Information</h3>
</div>
<div class="panel-body">
<!-- <div class="form-group">
<label for="">ID</label>
<input type="text" value="<?php echo $transaction['id'] ?>" class="form-control" name="id" id="" disabled>
</div> -->
<div class="form-row">
<div class="form-group col-md-6">
<label for="">Name</label>
<input type="text" value="<?php echo $transaction['user_name'] ?>" class="form-control" name="name" id="" disabled>
</div>
<div class="form-group col-md-6">
<label for="">Contact</label>
<input type="text" value="<?php echo $transaction['phone'] ?>" class="form-control" name="name" id="" disabled>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="">Advance</label>
<input type="number" value="<?php echo $transaction['advance'] ?>" class="form-control" name="advance" id="">
</div>
<div class="form-group col-md-6">
<label for="">Total</label>
<input type="number" value="<?php echo $transaction['total'] ?>" class="form-control" name="total" id="">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="">Cash</label>
<input type="number" value="<?php echo $transaction['cash'] ?>" class="form-control" name="total" id="" disabled>
</div>
<div class="form-group col-md-6">
<label for="">Due</label>
<input type="number" value="<?php echo $transaction['due'] ?>" class="form-control" name="due" id="" disabled>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="method">Payment Method:</label>
<select class="form-control" id="method" name="method" required>
<option value="" <?php echo ($transaction['method'] == '') ? 'selected' : ''; ?>>--Select--</option>
<option value="bkash" <?php echo ($transaction['method'] == 'bkash') ? 'selected' : ''; ?>>BKash</option>
<option value="nagad" <?php echo ($transaction['method'] == 'nagad') ? 'selected' : ''; ?>>Nagad</option>
<option value="cash" <?php echo ($transaction['method'] == 'cash') ? 'selected' : ''; ?>>Cash</option>
</select>
</div>
<div class="form-group col-md-12 text-center">
<input class="btn btn-primary" type="submit" name="submit" value="Update Transaction">
<a class="btn btn-info" href="transaction.php">List All Transaction</a>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php
include_once('includes/footer.php');
?>