-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathallocation-report.php
213 lines (185 loc) · 8.33 KB
/
allocation-report.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
<?php
include 'authenticate.php';
$role = isset($_SESSION['role']) ? $_SESSION['role'] : 'guest';
checkUser($role);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Allocation Details</title>
<link rel="icon" type="image/webp" href="logo.webp" />
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="allocation-report.css">
</head>
<body>
<header>
<div class="header-top">
<a href="./">
<h1>East Coast Railway</h1>
<h1>Closed User Group</h1>
</a>
</div>
</header>
<main>
<section id="allocation-details">
<div class="heading-container">
<button class="back-btn" id="roleRedirectButton" data-role="<?php echo $role; ?>">
<img src="icon/back-button.webp" alt="back button">
</button>
<h2 class="heading">Allocation Report</h2>
</div>
<!-- Form for selecting month and year -->
<form class="form_container" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div class="input_box">
<label for="month">Select Month:</label>
<select id="month" name="month">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</div>
<div class="input_box">
<label for="year">Select Year:</label>
<select id="year" name="year">
<?php
// Generate options for years, assuming a range of 50 years from current year
$currentYear = date('Y');
for ($i = 0; $i < 50; $i++) {
$year = $currentYear - $i;
echo '<option value="' . $year . '">' . $year . '</option>';
}
?>
</select>
</div>
<button class="action-button long-input" type="submit">Filter</button>
</form>
<?php
// Include database connection file
include 'db_connect.php';
// Default month and year to current month and year
$selectedMonth = isset($_GET['month']) ? $_GET['month'] : "01";
$selectedYear = isset($_GET['year']) ? $_GET['year'] : date('Y');
// Fetch GST percentages
$gst_query = "SELECT cgst_percentage, sgst_percentage FROM gst LIMIT 1";
$gst_result = $conn->query($gst_query);
$gst_data = $gst_result->fetch_assoc();
$cgst_percentage = $gst_data['cgst_percentage'];
$sgst_percentage = $gst_data['sgst_percentage'];
// SQL query to fetch and aggregate data for selected month and year
$query = "
SELECT
c.allocation,
GROUP_CONCAT(DISTINCT CONCAT(b.bill_month, '-', b.bill_year) ORDER BY b.bill_year, b.bill_month ASC SEPARATOR ', ') AS bill_dates,
SUM(b.periodic_charge + b.usage_amount + b.data_amount + b.voice + b.video + b.sms + b.vas) AS total_amount
FROM
cugdetails c
JOIN
bills b ON c.cug_number = b.cug_number
WHERE
b.bill_month = '$selectedMonth' AND b.bill_year = '$selectedYear'
GROUP BY
c.allocation
ORDER BY
c.allocation;
";
$result = $conn->query($query);
if ($result->num_rows > 0) {
echo '<table border="1">';
echo '<tr><th>Allocation</th><th>Bill Dates</th><th>Amount</th></tr>';
$grand_total_amount = 0;
while ($row = $result->fetch_assoc()) {
$total_amount = $row['total_amount'];
$grand_total_amount += $total_amount;
echo '<tr>';
echo '<td>' . $row['allocation'] . '</td>';
echo '<td>' . $row['bill_dates'] . '</td>';
echo '<td> Rs. ' . number_format($total_amount, 2) . '</td>';
echo '</tr>';
}
echo '<tr class="transparent-row"><td colspan="3"><hr></td></tr>';
$grand_total_cgst = ($grand_total_amount * $cgst_percentage) / 100;
$grand_total_sgst = ($grand_total_amount * $sgst_percentage) / 100;
$grand_total_payable = $grand_total_amount + $grand_total_cgst + $grand_total_sgst;
echo '<tr>';
echo '<td colspan="2" style="text-align: right;">Grand Total :</td>';
echo '<td> Rs. ' . number_format($grand_total_amount, 2) . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan="2" style="text-align: right;">CGST ₹</td>';
echo '<td> Rs. ' . number_format($grand_total_cgst, 2) . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan="2" style="text-align: right;">SGST ₹</td>';
echo '<td> Rs. ' . number_format($grand_total_sgst, 2) . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan="2" style="text-align: right;">Total Payable :</td>';
echo '<td> Rs. ' . number_format($grand_total_payable, 2) . '</td>';
echo '</tr>';
echo '</table>';
} else {
echo '<p class="session-message error">No data found for selected month and year.</p>';
}
// Close database connection
$conn->close();
?>
<form method="post" action="generate_pdf_allocation.php">
<input type="hidden" name="month" value="<?php echo $selectedMonth; ?>">
<input type="hidden" name="year" value="<?php echo $selectedYear; ?>">
<button class="action-button" type="submit" name="generate_pdf">Generate PDF</button>
</form>
</section>
</main>
<footer>
<p>© 2024 East Coast Railway. All rights reserved.</p>
<div class="footer-links">
<a href="#">Privacy Policy</a>
<a href="#">Terms of Service</a>
</div>
</footer>
<script>
document.addEventListener("DOMContentLoaded", function ()
{
// Role based Redirection -------------------------
const redirectButton = document.getElementById("roleRedirectButton");
const userRole = redirectButton.getAttribute("data-role");
redirectButton.addEventListener("click", function ()
{
if (userRole === 'admin')
{
window.location.href = 'admin-page.php';
} else if (userRole === 'dealer')
{
window.location.href = 'dealer-page.php';
} else
{
alert("Error: Unexpected role. Please login again.");
}
});
// Set month and year based on URL parameters
const urlParams = new URLSearchParams(window.location.search);
const month = urlParams.get('month');
const year = urlParams.get('year');
if (month)
{
document.getElementById('month').value = month;
}
if (year)
{
document.getElementById('year').value = year;
}
});
</script>
</body>
</html>