File "report_in.php"
Full path: /home/atrmarke/public_html/atrdemolive.site/bshop/log/report_in.php
File
size: 0.01 KB (12.81 KB bytes)
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
include("db/cn.php");
ob_start();
if (isset($_SESSION['user_name']) && isset($_SESSION['user_role']) && isset($_SESSION['outlet_name']) && isset($_SESSION['outlet_address'])) {
$userName = $_SESSION['user_name'];
$userRole = $_SESSION['user_role'];
$outlet_address = $_SESSION['outlet_address'];
$outlet_name = $_SESSION['outlet_name'];
}
ob_end_flush();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Invoice Reporting</title>
<!-- Bootstrap CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<link rel="stylesheet" href="css/custom_css.css" />
<!-- jsPDF and AutoTable -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.20/jspdf.plugin.autotable.min.js"></script>
</head>
<style>
#table-container-wrapper {
max-height: 460px; /* Adjust the maximum height as needed */
overflow-y: auto; /* Enable vertical scroll when content overflows */
}
@media (max-width: 880px) {
.col-4 {
width: 33.33% !important;
}
.fa-wifi {
display: none !important;
}
.col-6 {
width: 50% !important;
}
}
@media (min-width: 880px) {
.sidebar {
width: 100%;
/* Change sidebar width to 100% on mobile */
max-width: 120px; /* Set maximum width for the sidebar */
}
}
@media (min-width: 880px) {
.main-content {
margin-left: ; /* Width of the sidebar */
}
}
/* Added new class to control overlay */
.overlay {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.6);
z-index: 999;
display: none; /* Initially hidden */
} /* Custom styles for sidebar */
.sidebar {
width: 100px;
background: linear-gradient(180deg, #503F2E, #060606);
position: fixed;
bottom: 0;
top: 60px;
transition: transform 0.3s ease-in-out;
transform: translateX(0);
z-index: 1;
height: 100%;
border-radius: 0px;
transition: transform 0.3s ease-in-out, width 0.3s ease-in-out;
}
.sidebar.hide {
transform: translateX(-100px);
/* Move sidebar out of the viewport when it is hidden */
}
.sidebar .nav-item {
padding: 10px 0;
text-align: center;
position: relative;
font-size: 12px;
}
.sidebar .nav-link {
color: #fff;
position: relative;
/* Ensure icon and text are positioned relative to the nav link */
z-index: 2;
/* Ensure the text and icon are above the hover background */
}
.sidebar .nav-link i {
margin-bottom: 5px;
/* Adjust the margin of the icon */
}
/* Custom styles for hover effect */
.sidebar .nav-item:hover:after {
background-color: #fff;
content: '';
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
z-index: 1;
/* Ensure the hover background is below the text and icon */
}
.sidebar .nav-item:hover .nav-link {
color: #0A4A5D;
}
/* Custom styles for divider */
.sidebar .nav-item:after {
content: "";
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 1px;
background-color: #fff;
transition: height 0.3s ease-in-out;
/* Transition effect for smooth animation */
}
/* Custom styles for header */
.header {
background: linear-gradient(100deg, #503F2E, #060606);
color: #fff;
padding: 10px;
position: fixed;
top: 0;
width: 100%;
z-index: 2;
height: 69px;
box-shadow: #FFF 2px 0px 0px 0px;
/* Ensure header appears above sidebar */
}
.header .navbar-toggler {
color: #fff;
}
.header .navbar-toggler-icon {
color: #fff;
/* Set the color of the toggle button to white */
}
.header .navbar-toggler.white {
color: #fff !important;
/* Ensure the toggle button is white */
}
.header .navbar-brand {
color: #fff;
/* Set navbar brand text color to white */
}
.header .nav-item .nav-link {
color: #fff;
/* Set nav link text color to white */
}
.main-content {
margin-top: 50px; /* Height of fixed header */
margin-left: 70px; /* Initially, set margin-left to 0 */
padding-top: 30px; /* Height of fixed header */
transition: margin-left 0.3s ease-in-out; /* Add transition for smoother animation */
}
/* Custom styles for search bar */
.search-container {
display: flex;
align-items: center;
width:100%;
margin: 2px auto;
float:left;
}
/* Updated hide class to apply to the overlay */
.sidebar.hide, .overlay.hide {
transform: translateX(-100%);
}
.search-input {
width: 100%;
padding: 10px 30px 10px 10px;
/* Adjust padding to accommodate the icon */
border: 1px solid #ccc;
border-radius: 20px;
font-size: 16px;
}
.search-icon {
position: relative;
left: -25px;
/* Adjust the position of the icon */
color: #aaa;
}
.search-icon i {
position: absolute;
top: 50%;
transform: translateY(-50%);
} .btn-dark {
background: #503F2E;
color: #fff;
border: 1px solid #503F2E;
}
.btn-dark:hover {
background: #fff;
color: #503F2E;
border: 1px solid #503F2E;
}
.bg-dark2 {
background: #503F2E;
color: #fff;
}
.modal-content {
animation: modal-animation 0.5s;
}
@keyframes modal-animation {
from {
opacity: 0;
transform: scale(0.8);
}
to {
opacity: 1;
transform: scale(1);
}
}
.card {
transition: all 0.3s ease-in-out;
padding:10px;
}
.card:hover {
background: #503F2E;
color: #fff;
box-shadow: 0 0 15px rgba(10, 74, 93, 0.7); /* Soft glow effect with color #1A5319 and opacity */
border-radius: 10px;
border:1px solid #fff;
}
</style>
</style>
<body>
<?php include("common/hd.php"); ?>
<?php include("common/sd.php"); ?>
<div class="main-content">
<div class="container mt-5">
<div class="row">
<div class="col-sm-3">
<h2 style="width:405px; height:66px; text-align:center; background:#503F2E; color:#fff; padding:12px; border-radius:10px;">Invoice Report</h2>
</div>
<div class="col-sm-6"></div>
<div class="col-sm-3">
<a href="report_p.php" class="btn btn-dark" style="margin-top:10px;float:right;">Back</a>
</div>
</div>
<br>
<form method="POST" action="">
<div class="row">
<div class="form-group col-3">
<label>Payment Method:</label>
<select id="paid" name="paid" class="form-control">
<option value="">Select</option>
<option value="cash">Cash</option>
<option value="credit">Credit</option>
<option value="bank1">Bank 1</option>
<option value="bank2">Bank 2</option>
<option value="bank3">Bank 3</option>
</select>
</div>
<div class="col-sm-12">
<div class="row">
<div class="form-group col-4">
<label for="start_date">Start Date:</label>
<input type="date" id="start_date" name="start_date" class="form-control" required>
</div>
<div class="form-group col-4">
<label for="end_date">End Date:</label>
<input type="date" id="end_date" name="end_date" class="form-control" required>
</div>
<div class="form-group col-4" style="margin-top:30px;">
<button type="submit" class="btn btn-dark">Filter</button>
<button id="downloadExcel" type="submit" class="btn btn-dark">Download</button>
<a href="report_in.php"><button type="button" class="btn btn-dark"><i class="fas fa-sync-alt fa-1x"></i></button></a>
</div>
</div>
</div>
</div>
</form>
</div>
<div class="container" id="table-container-wrapper">
<?php
// Check connection
if ($connection->connect_error) {
die("Connection failed: " . $connection->connect_error);
}
if (isset($_POST['start_date']) && isset($_POST['end_date'])) {
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
$paid_by = isset($_POST['paid']) ? $_POST['paid'] : '';
// Construct the SQL query using LIKE for the paid_by filter
$query = "SELECT date_time, order_id, customer_name, customer_phone, discount_amount, paid_by, SUM(discount_amount) AS total_amount
FROM log_user_sales
WHERE date_time BETWEEN ? AND ?
AND paid_by LIKE ?
GROUP BY order_id";
// Prepare the SQL query
$stmt = $connection->prepare($query);
// Use '%' for "All" payment methods, otherwise use the exact payment method
$paid_by_param = !empty($paid_by) ? $paid_by : '%';
$stmt->bind_param("sss", $start_date, $end_date, $paid_by_param);
// Execute the query
$stmt->execute();
$result = $stmt->get_result();
// Display results in a table
echo "<table id='patientTable' class='table table-striped table-sm text-center'>";
echo "<tr class='bg-dark text-white'>
<th>Date/Time</th>
<th>Order ID</th>
<th>Customer Name</th>
<th>Customer Phone</th>
<th>Discount Amount(Rs)</th>
<th>Paid By</th>
</tr>
";
$grandTotal = 0; // To calculate the grand total of all discounts
while ($row = $result->fetch_assoc()) {
echo "<tr>
<td>{$row['date_time']}</td>
<td>{$row['order_id']}</td>
<td>{$row['customer_name']}</td>
<td>{$row['customer_phone']}</td>
<td>{$row['discount_amount']}</td>
<td style='text-transform:capitalize;'>{$row['paid_by']}</td>
</tr>";
$grandTotal += $row['discount_amount'];
}
echo "
</table>";
// Display the grand total
// Close the statement and connection
$stmt->close();
}
$connection->close();
?>
</div>
<?php echo "<h3 style='margin-left:240px;'>Total Amount: $grandTotal</h3>";?>
</div>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.16.9/xlsx.full.min.js"></script>
<!-- JavaScript for exporting the table data to Excel -->
<script>
document.getElementById('downloadExcel').addEventListener('click', function() {
// Get the table element
var table = document.getElementById('patientTable');
// Clean the table to avoid potential issues with hidden rows or formatting
var clone = table.cloneNode(true); // Clone the table
var rows = clone.querySelectorAll('tr');
// Remove hidden or empty rows if necessary
rows.forEach(function(row) {
if (row.style.display === 'none' || row.innerText.trim() === '') {
row.remove();
}
});
// Convert the table into a worksheet using SheetJS
var workbook = XLSX.utils.table_to_book(clone, { sheet: "Patients" });
// Export the Excel file with a proper name
try {
XLSX.writeFile(workbook, 'Invoice_data.xlsx');
} catch (error) {
console.error("Error while writing the file: ", error);
alert("Error generating Excel file. Please check if the SheetJS library is properly loaded.");
}
});
</script>
</html>