File "declined_payment_proof.php"

Full Path: /home/leadltht/fastlinkinternet.com/administrator/data-provider/admin/declined_payment_proof.php
File size: 6.52 KB
MIME-type: text/x-php
Charset: utf-8

<?php
// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);

if (session_status() == PHP_SESSION_NONE) {
    session_start();
}

// Database connection
$conn = new mysqli("server329", "leadltht_prazey1982", "prazey1982123456", "leadltht_fastlinkinternet");

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Handle form submission for deletion
if (isset($_POST['delete'])) {
    $id = $_POST['id'];

    $delete_sql = "DELETE FROM pop WHERE ID = ?";
    $stmt = $conn->prepare($delete_sql);
    if ($stmt === false) {
        die("Error preparing statement: " . $conn->error);
    }
    $stmt->bind_param('i', $id);

    if ($stmt->execute()) {
        echo "<script>alert('Payment proof deleted successfully.'); window.location.href = 'declined_payment_proof.php';</script>";
    } else {
        echo "Error deleting record: " . $stmt->error;
    }
}

// Fetch years for the filter dropdown
$years = $conn->query("SELECT DISTINCT YEAR(PaymentDate) as year FROM pop WHERE Status = 'Declined' ORDER BY year DESC");

// Set default year and month to current year and month
$year = isset($_GET['year']) ? $_GET['year'] : date('Y');
$month = isset($_GET['month']) ? $_GET['month'] : date('m');

// Fetch declined payment proofs based on the selected year and month
$sql = "SELECT * FROM pop WHERE Status = 'Declined' AND YEAR(PaymentDate) = ? AND MONTH(PaymentDate) = ? ORDER BY PaymentDate DESC";
$stmt = $conn->prepare($sql);
if ($stmt === false) {
    die("Error preparing statement: " . $conn->error);
}
$stmt->bind_param('ii', $year, $month);
$stmt->execute();
$result = $stmt->get_result();
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Declined Payment Proofs</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
    <style>
        @media print {
            .no-print {
                display: none;
            }
        }
    </style>
</head>
<body>
<div class="container mt-5">
    <h2 class="mb-4">Declined Payment Proofs</h2>
    <div class="mb-4 no-print">
        <a href="https://fastlinkinternet.com/administrator/data-provider/admin/?page=service_request_dashboard" class="btn btn-secondary">Back</a>
        <button class="btn btn-primary" onclick="window.print()">Print</button>
    </div>
    <div class="mb-4 no-print">
        <form method="get" action="declined_payment_proof.php">
            <div class="form-row">
                <div class="form-group col-md-4">
                    <label for="year">Year</label>
                    <select name="year" id="year" class="form-control">
                        <?php while ($row = $years->fetch_assoc()): ?>
                            <option value="<?php echo $row['year']; ?>" <?php echo $row['year'] == $year ? 'selected' : ''; ?>>
                                <?php echo $row['year']; ?>
                            </option>
                        <?php endwhile; ?>
                    </select>
                </div>
                <div class="form-group col-md-4">
                    <label for="month">Month</label>
                    <select name="month" id="month" class="form-control">
                        <?php for ($i = 1; $i <= 12; $i++): ?>
                            <option value="<?php echo str_pad($i, 2, '0', STR_PAD_LEFT); ?>" <?php echo $i == $month ? 'selected' : ''; ?>>
                                <?php echo date('F', mktime(0, 0, 0, $i, 1)); ?>
                            </option>
                        <?php endfor; ?>
                    </select>
                </div>
                <div class="form-group col-md-4 align-self-end">
                    <button type="submit" class="btn btn-primary">Filter</button>
                </div>
            </div>
        </form>
    </div>
    <div class="table-responsive">
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>#</th>
                    <th>Payment Date</th>
                    <th>Receipt Number</th>
                    <th>Payment Method</th>
                    <th>Client Name</th>
                    <th>Amount Received</th>
                    <th>Amount Paid</th>
                    <th>Status</th>
                    <th class="no-print">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php if ($result->num_rows > 0) { 
                    $counter = 1; ?>
                    <?php while ($row = $result->fetch_assoc()) { ?>
                        <tr>
                            <td><?php echo $counter++; ?></td>
                            <td><?php echo htmlspecialchars($row['PaymentDate']); ?></td>
                            <td><?php echo htmlspecialchars($row['ReceiptNumber']); ?></td>
                            <td><?php echo htmlspecialchars($row['PaymentMethod']); ?></td>
                            <td><?php echo htmlspecialchars($row['ClientName']); ?></td>
                            <td><?php echo htmlspecialchars($row['AmountReceived']); ?></td>
                            <td><?php echo htmlspecialchars($row['AmountPaid']); ?></td>
                            <td><?php echo htmlspecialchars($row['Status']); ?></td>
                            <td class="no-print">
                                <form method="post" action="" onsubmit="return confirm('Are you sure you want to delete this payment proof?');">
                                    <input type="hidden" name="id" value="<?php echo htmlspecialchars($row['id']); ?>">
                                    <button type="submit" name="delete" class="btn btn-danger">Delete</button>
                                </form>
                            </td>
                        </tr>
                    <?php } ?>
                <?php } else { ?>
                    <tr>
                        <td colspan="9" class="text-center">No declined payment proofs found for the selected period.</td>
                    </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</body>
</html>

<?php
$conn->close();
?>