:: **Zploit** v1.0 | Current Path: **/home/kreativepixelz/www/crm/quatation/**
:: Editing File: sales_report.php
<?php include_once("session.php"); include("db.php"); include("header.php"); // Filters $from_date = $_GET['from_date'] ?? ''; $to_date = $_GET['to_date'] ?? ''; // Build query $sql = "SELECT id, sale_date, customer_name, total_amount, cost_amount, remarks FROM sales WHERE 1=1"; if ($from_date) { $sql .= " AND sale_date >= '" . mysqli_real_escape_string($conn, $from_date) . "'"; } if ($to_date) { $sql .= " AND sale_date <= '" . mysqli_real_escape_string($conn, $to_date) . "'"; } $sql .= " ORDER BY sale_date DESC"; $result = mysqli_query($conn, $sql); if (!$result) { die("Query failed: " . mysqli_error($conn)); } ?> <main class="container-fluid"> <div class="row m-1"> <div class="col-12"> <h4 class="main-title">Sales / Profit Report</h4> <ul class="app-line-breadcrumbs mb-3"> <li><a href="dashboard.php">Home</a></li> <li class="active">Sales Report</li> </ul> </div> </div> <!-- Filter Form --> <div class="card mb-3"> <div class="card-body"> <form class="row g-3" method="get" action=""> <div class="col-md-4"> <label class="form-label">From Date</label> <input type="date" class="form-control" name="from_date" value="<?= htmlspecialchars($from_date) ?>"> </div> <div class="col-md-4"> <label class="form-label">To Date</label> <input type="date" class="form-control" name="to_date" value="<?= htmlspecialchars($to_date) ?>"> </div> <div class="col-md-4 d-flex align-items-end"> <button type="submit" class="btn btn-primary w-100">Filter</button> </div> </form> </div> </div> <!-- Report Table --> <div class="card"> <div class="card-body table-responsive"> <table class="table table-bordered table-striped"> <thead> <tr> <th>Sale ID</th> <th>Date</th> <th>Customer</th> <th>Total Amount (₹)</th> <th>Cost (₹)</th> <th>Profit (₹)</th> <th>Remarks</th> </tr> </thead> <tbody> <?php $grand_total = 0; $grand_cost = 0; $grand_profit = 0; if (mysqli_num_rows($result) > 0): while ($row = mysqli_fetch_assoc($result)): $profit = $row['total_amount'] - $row['cost_amount']; $grand_total += $row['total_amount']; $grand_cost += $row['cost_amount']; $grand_profit += $profit; ?> <tr> <td><?= $row['id'] ?></td> <td><?= date("d-m-Y", strtotime($row['sale_date'])) ?></td> <td><?= htmlspecialchars($row['customer_name']) ?></td> <td><?= number_format($row['total_amount'], 2) ?></td> <td><?= number_format($row['cost_amount'], 2) ?></td> <td><?= number_format($profit, 2) ?></td> <td><?= htmlspecialchars($row['remarks']) ?></td> </tr> <?php endwhile; ?> <tr class="table-info fw-bold"> <td colspan="3" class="text-end">TOTAL</td> <td><?= number_format($grand_total, 2) ?></td> <td><?= number_format($grand_cost, 2) ?></td> <td><?= number_format($grand_profit, 2) ?></td> <td></td> </tr> <?php else: ?> <tr><td colspan="7" class="text-center">No sales records found</td></tr> <?php endif; ?> </tbody> </table> </div> </div> </main> <?php include("footer.php"); ?>