-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.php
257 lines (236 loc) · 11.5 KB
/
transaction.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
session_start();
if (!isset($_SESSION['id']) || !isset($_SESSION['role'])) {
header('Location: login.php');
exit;
}
include 'connection.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Check if the "status" button is clicked
if (isset($_POST['updatestatus']) && isset($_POST['transactionId'])) {
$transactionId = $_POST['transactionId'];
// Retrieve the current "due" and "cash" values
$query = "SELECT due, cash FROM transaction WHERE id = $transactionId";
$result = mysqli_query($conn, $query);
if ($row = mysqli_fetch_assoc($result)) {
$dueValue = $row['due'];
$cashValue = $row['cash'];
$status = $row['status'];
// Perform the update to set "due" to 0 and add "due" to "cash"
$updateQuery = "UPDATE transaction SET due = 0, status = 1, cash = cash + $dueValue WHERE id = $transactionId";
$updateResult = mysqli_query($conn, $updateQuery);
if ($updateResult) {
// Redirect or perform any additional actions after the update
header('Location: transaction.php');
exit;
} else {
// Handle the update failure
echo "Failed to update due value and add to cash.";
}
} else {
// Handle error if the transaction ID is not valid
echo "Invalid transaction ID.";
}
}
}
include_once('includes/header.php');
?>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-zt4p0WigVNZ71UKsgm3q2Kd6BP3sXcFRwhPQc9zLbU/GyZHPsAxe90BRsdMr1yejzEFB5xbjNc9PnByhJkTKZw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
#page-wrapper {
text-align: center;
}
#yourTableID {
margin: 0 auto;
width: 80%;
}
</style>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Transaction</h1>
</div>
</div>
<div class="row">
<div class="table-responsive">
<table id="yourTableID" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<th>Date</th>
<th>Contact</th>
<th>Advance</th>
<th>Cash</th>
<th>Due</th>
<th>Total</th>
<th>Method</th>
<th>Action</th>
<th>Status</th>
<th>Invoice</th>
</thead>
<tbody>
<?php
$query = "SELECT transaction.*, customers.phone as phone
FROM transaction
LEFT JOIN customers ON transaction.user_id = customers.id
ORDER BY transaction.due DESC";
$sql = mysqli_query($conn, $query);
while ($row = mysqli_fetch_array($sql)) { ?>
<tr>
<td><?php
$temp = $row['created_at'];
$dates = explode(' ', $temp);
echo $dates[0];
?></td>
<td><?php echo $row['phone'] ?></td>
<td><?php echo $row['advance'] ?></td>
<td><?php echo $row['cash'] ?></td>
<td><?php echo $row['due'] ?></td>
<td><?php echo $row['total'] ?></td>
<td><?php echo $row['method'] ?></td>
<td>
<a class="btn btn-primary" href="editTransaction.php?id=<?php echo $row['id'] ?>">Edit</a>
</td>
<td>
<?php
// Set button color and label based on the value of "Due" and "Status"
$buttonColor = ($row['due'] == 0) ? 'btn-success' : 'btn-danger';
$buttonLabel = ($row['due'] == 0) ? 'Paid' : 'Unpaid';
// Output the button with dynamic color and label, conditionally disabling it
echo '<form method="post" action="">
<input type="hidden" name="transactionId" value="' . $row['id'] . '">
<button type="submit" class="btn ' . $buttonColor . '" name="updatestatus" ' . ($row['due'] == 0 && $row['status'] == 1 ? 'disabled' : '') . '>' . $buttonLabel . '</button>
</form>';
?>
</td>
<td><a style="display: inline-block; font-size: 30px; text-align: center; text-decoration: none; color: #fff; border-radius: 5px; " href="invoice.php?id=<?php echo $row['id'] ?>">
<svg style="margin-right: 10px; color: #ffd700; font-size: 30px;" class="fas fa-file-invoice" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30" width="30" height="30">
<path d="M4 1h16a2 2 0 0 1 2 2v18a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2zm14 6H6a1 1 0 0 0 0 2h12a1 1 0 0 0 0-2zM6 14h12a1 1 0 0 0 0-2H6a1 1 0 0 0 0 2zm0 4h12a1 1 0 0 0 0-2H6a1 1 0 0 0 0 2z" />
</svg>
</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Include jQuery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<!-- Include DataTables CSS and JS -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css">
<script type="text/javascript" src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.js"></script>
<!-- Include DataTables Buttons CSS and JS -->
<!-- <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/2.4.2/css/buttons.dataTables.min.css"> -->
<!-- <script type="text/javascript" src="https://cdn.datatables.net/buttons/2.4.2/js/dataTables.buttons.min.js"></script> -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
<!-- <script type="text/javascript" src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.html5.min.js"></script> -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
<!-- Include DataTables Responsive CSS and JS -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/2.2.9/css/responsive.dataTables.min.css">
<script type="text/javascript" src="https://cdn.datatables.net/responsive/2.2.9/js/dataTables.responsive.min.js"></script>
<!-- Include DataTables Buttons CSS and JS -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/2.4.2/css/buttons.dataTables.min.css">
<script type="text/javascript" src="https://cdn.datatables.net/buttons/2.4.2/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.html5.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
<script>
$(document).ready(function() {
$('#yourTableID').DataTable({
"dom": '<"row mb-3"<"col-sm-12 col-md-6"l><"col-sm-12 col-md-6"f>>' +
'<"row"<"col-sm-12"B>>' +
'<"row"<"col-sm-12"tr>>' +
'<"row"<"col-sm-12 col-md-5"i><"col-sm-12 col-md-7"p>>',
"paging": true,
"autoWidth": true,
responsive: true,
order: [[4, 'desc']],
"buttons": [{
extend: 'copyHtml5',
className: 'btn btn-success',
text: 'Copy to Clipboard',
exportOptions: {
title: function() {
return 'Custom File Name - Copy';
}
}
},
{
extend: 'csvHtml5',
className: 'btn btn-warning',
text: 'Export to CSV',
exportOptions: {
title: function() {
return 'Custom File Name - CSV';
}
}
},
{
extend: 'excelHtml5',
className: 'btn btn-primary',
text: 'Export to Excel',
exportOptions: {
title: function() {
return 'Custom File Name - Excel';
}
}
},
{
extend: 'pdfHtml5',
className: 'btn btn-danger',
text: 'Export to PDF',
exportOptions: {
title: function() {
return 'Custom File Name - PDF';
}
}
},
'print'
],
"lengthMenu": [
[10, 25, 50, -1],
[10, 25, 50, "All"]
],
"pageLength": 10,
"language": {
"lengthMenu": "Show _MENU_ entries per page",
"zeroRecords": "No matching records found",
"info": "Showing _START_ to _END_ of _TOTAL_ entries",
"infoEmpty": "Showing 0 to 0 of 0 entries",
"infoFiltered": "(filtered from _MAX_ total entries)",
"paginate": {
"first": "First",
"previous": "Previous",
"next": "Next",
"last": "Last"
}
},
"initComplete": function(settings, json) {
// Apply custom styling to the buttons
var buttons = $('.dt-buttons button');
buttons.css({
'background-color': '#337ab7',
'border-radius': '5px',
'color': '#fff',
'transition': 'background-color 0.3s ease, border-radius 0.3s ease'
});
// Add hover effect
buttons.hover(
function() {
$(this).css('background-color', '#2d70aa');
},
function() {
$(this).css('background-color', '#337ab7');
}
);
var searchInput = $('.dataTables_filter input');
// searchInput.addClass('form-control rounded-pill'); // Bootstrap class for input styling and border-radius
searchInput.attr('placeholder', 'Search...');
}
});
});
</script>
<?php include_once('includes/footer.php'); ?>