D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
inventory.tapaslights.com
/
Filename :
material_transaction.php
back
Copy
<?php include 'config.php'; // Build filter conditions $conditions = []; if (!empty($_GET['from_date'])) { $from = $_GET['from_date'] . " 00:00:00"; $conditions[] = "created_at >= '" . $conn->real_escape_string($from) . "'"; } if (!empty($_GET['to_date'])) { $to = $_GET['to_date'] . " 23:59:59"; $conditions[] = "created_at <= '" . $conn->real_escape_string($to) . "'"; } if (!empty($_GET['transaction_type'])) { $conditions[] = "transaction_type = '" . $conn->real_escape_string($_GET['transaction_type']) . "'"; } $whereClause = $conditions ? "WHERE " . implode(" AND ", $conditions) : ""; // Export logic if (isset($_GET['export']) && in_array($_GET['export'], ['csv', 'excel'])) { $ext = $_GET['export']; $filename = "material_transactions_" . date("Ymd_His") . ".$ext"; $query = "SELECT * FROM material_transactions $whereClause ORDER BY created_at DESC"; $result = $conn->query($query); header("Content-Type: application/" . ($ext === 'excel' ? 'vnd.ms-excel' : 'csv')); header("Content-Disposition: attachment; filename=\"$filename\""); $output = fopen("php://output", "w"); fputcsv($output, ['Date', 'Material Name', 'Transaction Type', 'Quantity', 'Unit', 'Price/Unit', 'Total Price']); while ($row = $result->fetch_assoc()) { fputcsv($output, [ date('d M Y, h:i A', strtotime($row['created_at'])), $row['material_name'], ucfirst($row['transaction_type']), $row['quantity'], $row['unit'], number_format($row['price_per_unit'], 2), number_format($row['total_price'], 2), ]); } fclose($output); exit; } // Pagination setup $limit = 10; $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; $offset = ($page - 1) * $limit; // Get total rows $countQuery = "SELECT COUNT(*) as total FROM material_transactions $whereClause"; $totalResult = $conn->query($countQuery)->fetch_assoc(); $totalRows = $totalResult['total']; $totalPages = ceil($totalRows / $limit); // Get current page rows $query = "SELECT * FROM material_transactions $whereClause ORDER BY created_at DESC LIMIT $limit OFFSET $offset"; $result = $conn->query($query); ?> <!DOCTYPE html> <html lang="en" data-layout="vertical" data-topbar="light" data-sidebar="light" data-sidebar-size="lg" data-sidebar-image="none"> <head> <?php include 'style.php'; ?> </head> <body> <div class="main-wrapper"> <?php include 'header.php'; ?> <?php include 'sidebar.php'; ?> <div class="page-wrapper"> <div class="content container-fluid"> <div class="row"> <div class="col-lg-12"> <div class="card"> <div class="card-header"> <h5 class="card-title">Material Transactions History</h5> </div> <div class="card-body table-responsive"> <!-- Filter Form --> <form class="row g-3 mb-4" method="GET" action=""> <div class="col-md-3"> <label class="form-label">From Date</label> <input type="date" class="form-control" name="from_date" value="<?= htmlspecialchars($_GET['from_date'] ?? '') ?>"> </div> <div class="col-md-3"> <label class="form-label">To Date</label> <input type="date" class="form-control" name="to_date" value="<?= htmlspecialchars($_GET['to_date'] ?? '') ?>"> </div> <div class="col-md-3"> <label class="form-label">Transaction Type</label> <select class="form-control" name="transaction_type"> <option value="">All</option> <option value="add" <?= (($_GET['transaction_type'] ?? '') === 'add') ? 'selected' : '' ?>>Addition</option> <option value="deduct" <?= (($_GET['transaction_type'] ?? '') === 'deduct') ? 'selected' : '' ?>>Deduction</option> </select> </div> <div class="col-md-3 d-flex align-items-end"> <button type="submit" class="btn btn-primary me-2">Filter</button> <a href="material_transactions.php" class="btn btn-secondary">Reset</a> </div> </form> <!-- Export Buttons --> <div class="mb-3"> <a href="?<?= http_build_query(array_merge($_GET, ['export' => 'csv'])) ?>" class="btn btn-outline-success btn-sm">Export CSV</a> <a href="export_pdf.php?<?= http_build_query($_GET) ?>" class="btn btn-outline-danger btn-sm">Export PDF</a> </div> <!-- Data Table --> <table class="table table-bordered table-hover"> <thead> <tr> <th>Date</th> <th>Material Name</th> <th>Transaction Type</th> <th>Quantity</th> <th>Unit</th> <th>Price/Unit</th> <th>Total Price</th> </tr> </thead> <tbody> <?php if ($result->num_rows > 0): ?> <?php while ($row = $result->fetch_assoc()): ?> <tr> <td><?= date('d M Y, h:i A', strtotime($row['created_at'])) ?></td> <td><?= htmlspecialchars($row['material_name']) ?></td> <td> <span class="badge bg-<?= $row['transaction_type'] == 'add' ? 'success' : 'danger' ?>"> <?= ucfirst($row['transaction_type']) ?> </span> </td> <td><?= $row['quantity'] ?></td> <td><?= htmlspecialchars($row['unit']) ?></td> <td>₹<?= number_format($row['price_per_unit'], 2) ?></td> <td>₹<?= number_format($row['total_price'], 2) ?></td> </tr> <?php endwhile; ?> <?php else: ?> <tr><td colspan="7" class="text-center">No transactions found.</td></tr> <?php endif; ?> </tbody> </table> <!-- Pagination --> <?php if ($totalPages > 1): ?> <nav> <ul class="pagination justify-content-center"> <?php for ($i = 1; $i <= $totalPages; $i++): ?> <li class="page-item <?= ($i == $page) ? 'active' : '' ?>"> <a class="page-link" href="?<?= http_build_query(array_merge($_GET, ['page' => $i])) ?>"><?= $i ?></a> </li> <?php endfor; ?> </ul> </nav> <?php endif; ?> </div> </div> </div> </div> </div> </div> </div> <?php include 'footer.php'; ?> </body> </html>